in reply to Got those HTML::Template and subroutine blues
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (2) Got those HTML::Template and subroutine blues (chipmunk++)
by ybiC (Prior) on Dec 23, 2000 at 00:11 UTC | |
by chipmunk (Parson) on Dec 23, 2000 at 00:48 UTC | |
by repson (Chaplain) on Dec 31, 2000 at 05:38 UTC |