in reply to HTML::Template Maintainability
Your template uses a loop to build the list so your parameter list needs an entry for the loop containing a list of the name/value pairs used to populate the list entries. Consider:
#!/usr/bin/perl use strict; use warnings; use HTML::Template; my $html = <<HTML; <DIV CLASS='menu_bar'><tmpl_if name=menu_options> <UL CLASS='main_menu'> <tmpl_loop name=menu_options> <LI CLASS='main_menu'> <A CLASS='main_menu' HREF='<tmpl_var name=option_address>'> +<tmpl_var name=option_name></A> </LI></tmpl_loop> </UL></tmpl_if> </div> HTML my @options = ("Home", "About", "Contact",); my %options_menu = ( Home => '/index.cgi', About => '/about.cgi', Contact => 'contact.cgi', ); my $tmpl = HTML::Template->new ( path => ['/path/to/'], scalarref => \$html, ); my %params; push @{$params{menu_options}}, {option_name => $_, option_address => $options_menu{$_}} for @options; $tmpl->param (%params); print $tmpl->output ();
Prints:
<DIV CLASS='menu_bar'> <UL CLASS='main_menu'> <LI CLASS='main_menu'> <A CLASS='main_menu' HREF='/index.cgi'>Home</A> </LI> <LI CLASS='main_menu'> <A CLASS='main_menu' HREF='/about.cgi'>About</A> </LI> <LI CLASS='main_menu'> <A CLASS='main_menu' HREF='contact.cgi'>Contact</A> </LI> </UL> </div>
|
|---|