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>
True laziness is hard work

In reply to Re: HTML::Template Maintainability by GrandFather
in thread HTML::Template Maintainability by PyrexKidd

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.