Inspired (outspired?) by Ovid's recent tutorial, I'm converting a handful of CGI.pm web pages to use HTML::Template.

So far, so good, except for hashes of URLs and text titles.   btrott, merlyn, and jcwren helped me get that going for CGI.pm a while back using map.   But now I'm at a loss for how to apply that to HTML::Template, even after reading the tutorial and modules docs.   Looks like it would involve <TEMPL_LOOP>, but my synapses just aren't synapping well today.

Thanks in advance for any direction, suggestions, or examples.
    cheers,
    Don
    striving for Perl Adept
    (it's pronounced "why-bick")

Hmmm... hope this <READMORE> tag works...


Here's a simplification of existing CGI.pm-only page (template-not.pl)

#!/usr/bin/perl -wT use strict; use CGI::Pretty qw(:all); use CGI::Carp qw(fatalsToBrowser); # during debugging #use CGI::Carp; # after debugging use Time::localtime; use File::stat; my $dtd = '-//W3C//DTD HTML 4.0 Transitional//EN'; my $servname = $ENV{'SERVER_NAME'}; my $file = 'template-not.pl'; my $filemod = ctime(stat($file)-> mtime); my %urlhash = ( b('home') => '/', b('sitedocs') => '/sitedocs.pl', b('switches') => '/switches.pl', b('netdocs') => '/netdocs.pl', ); print header(-type => 'text/html'), start_html( -title => "$servname", -dtd => "$dtd", ); print ( map { a({href => $urlhash{$_}}, $_), br } sort keys %urlhash ); print ( p, 'code update', ($filemod), end_html );

Now here's simplification of my HTML::Template code (template.pl)
#!/usr/bin/perl -wT use strict; use HTML::Template; use HTML::Entities; use CGI::Pretty qw(:all); use CGI::Carp qw(fatalsToBrowser); # during debugging #use CGI::Carp; # after debugging complete use Time::localtime; use File::stat; my $template = HTML::Template->new(filename => 'template.tmpl'); my $code = 'template.pl'; my $tmpl = 'template.tmpl'; $template-> param( CODEMOD => ctime(stat($code)-> mtime), TMPLMOD => ctime(stat($tmpl) -> mtime), SERVNAME => $ENV{'SERVER_NAME'}, ); # hash of URLs and text labels goes here somehow print header, $template->output;

And here's my simplified HTML::Template template (template.tmpl)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE><!-- TMPL_VAR NAME=SERVNAME --></TITLE> </HEAD> <BODY> TMP_LOOP(?) of %urlhash goes here <P> Code update <!-- TMPL_VAR NAME=CODEMOD --> <BR> Template update <!-- TMPL_VAR NAME=TMPLMOD --> </BODY> </HTML>

In reply to HTML::Template and hash o' links+labels by ybiC

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.