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 );
#!/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;
<!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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |