with a corresponding change to your template:my %tmpl_hash = ( urlloopA => { 'Home' => '/', 'Icons' => '/icons/', 'Sitedocs' => '/doc/', }, urlloopB => { 'Cisco' => 'http://www.cisco.com/', 'CPAN' => 'http://search.cpan.org/', 'Google' => 'http://www.google.com/', 'Perl Monks' => 'http://www.perlmonks.org/', }, ); for my $loop (keys %tmpl_hash) { my @vars; while (my($name, $url) = each %{$tmpl_hash{$loop}}) { push @vars, { name => $name, url => $url }; } $template->param($loop, [ @vars ]); }
The separate hashes become a hash of hashes and the separate loops become a nested loop.<!-- tmpl_loop name="urlloopA" --> <A HREF="<!-- tmpl_var name="url" -->"> <B><!-- tmpl_var name="name" --></B> </A> <!-- /tmpl_loop --> <P> <!-- tmpl_loop name="urlloopB" --> <A HREF="<!-- tmpl_var name="url" -->"> <!-- tmpl_var name="name" --> </A> <BR> <!-- /tmpl_loop -->
According to the HTML::Template docs, a TMPL_LOOP has its own scope; reusing the same variable names in different loops should work just fine.
In reply to Re: Got those HTML::Template and subroutine blues
by chipmunk
in thread Got those HTML::Template and subroutine blues
by ybiC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |