Fwd: tmpl_loop within a tmpl_loop - non-nested structure
"Brad Baxter" <[email protected]> Wed, 23 Apr 2008 11:21:51 -0400
| Newsgroups | gmane.comp.lang.perl.modules.html-template |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Apr 22, 2008 at 5:22 PM, Mertel, Mark <[email protected]> wrote: > So, I want to do this: > > <tmpl_loop loop> > > <tmpl_var name> > > <tmpl_loop list> > > <tmpl_var list_name> > > </tmpl_loop > > </tmpl_loop> > > > > Where 'list' is a separate array and not nested in the loop data > structure. > > Can I do this? > Short answer: no; or: it depends what you mean by 'separate'. To paraphrase the example in the docs: 1 #!/usr/local/bin/perl 2 3 use strict; 4 use warnings; 5 use HTML::Template; 6 7 my @array = <DATA>; 8 my $template = HTML::Template->new( arrayref => \@array ); 9 10 $template->param(loop => [ 11 { name => 'Bobby', 12 list => [ 13 { list_name => 'the big bad wolf' }, 14 { list_name => 'He-Man' }, 15 ], 16 }, 17 ], 18 ); 19 my $stuff = $template->output; 20 print $stuff; 21 22 23 __DATA__ 24 <tmpl_loop loop> 25 26 <tmpl_var name> 27 28 <tmpl_loop list> 29 30 <tmpl_var list_name> 31 32 </tmpl_loop> 33 34 </tmpl_loop> However, you could have a separate array whose reference you use in the param() call, e.g., 1 #!/usr/local/bin/perl 2 3 use strict; 4 use warnings; 5 use HTML::Template; 6 7 my @array = <DATA>; 8 my $template = HTML::Template->new( arrayref => \@array ); 9 my @list = ( 10 { list_name => 'the big bad wolf' }, 11 { list_name => 'He-Man' }, 12 ); 13 14 $template->param(loop => [ 15 { name => 'Bobby', 16 list => \@list, 17 }, 18 ], 19 ); 20 my $stuff = $template->output; 21 print $stuff; 22 23 24 __DATA__ 25 <tmpl_loop loop> 26 27 <tmpl_var name> 28 29 <tmpl_loop list> 30 31 <tmpl_var list_name> 32 33 </tmpl_loop> 34 35 </tmpl_loop> ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Html-template-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/html-template-users