http://qs1969.pair.com?node_id=509339

jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: TMPL_LOOP inside another TMPL_LOOP with HTML::Template
by marto (Cardinal) on Nov 17, 2005 at 09:23 UTC
    Hi jesuashok,

    "Is there a way to use TMPL_LOOP inside another TMPL_LOOP Example"
    This is covered in the HTML::Template documentation, it covers inner and outer loops. I am not sure exactly what thoughts you are looking for, other than you should read the documentation and give loops names.

    <TMPL_LOOP OUTER_LOOP> OUTER: <TMPL_VAR OUTER_VAR> <TMPL_LOOP INNER_LOOP> INNER: <TMPL_VAR INNER_VAR> INSIDE OUT: <TMPL_VAR OUTER_VAR> </TMPL_LOOP> </TMPL_LOOP>
    Update: You could also check out HTML::Template Tutorial by jeffa from the Tutorials section of the site.

    Hope this helps.

    Martin
Re: TMPL_LOOP inside another TMPL_LOOP with HTML::Template
by kulls (Hermit) on Nov 17, 2005 at 09:34 UTC
    Hi,
    here my sample..
    My template like this
    <select> <tmpl_loop loop_one> <option name='<tmpl_var name>'> <tmpl_var value> </option> <tmpl_if loop_two> <tmpl_loop loop_two> <option name='<tmpl_var name_one>'> <tmpl_var value_one> </option> </tmpl_loop> </tmpl_if> </tmpl_loop> </select>
    My prg is like this
    my (@loop_two,@loop_one); for(@arr_name) { push @loop_two, { name_one => 1, value_one => 2 }; } for(@arr_one) { push @loop_one, { name => 1, value => 2, loop_two => \@loop_two }; } $html->param(loop_one => \@loop_one); return $html->output(); where $html is HTML::Template object.

    -kulls
Re: TMPL_LOOP inside another TMPL_LOOP with HTML::Template
by jbrugger (Parson) on Nov 17, 2005 at 09:38 UTC
    #test.pl: use HTML::Template; my $tmpl = HTML::Template->new(filename => 'test.tmpl'); $tmpl->param( Loop1 => [ { Loop2 => [ {name => "me"}, {name=>"another"} ] }, { Loop2 => [ {name => "you" } ] }, ]); print $tmpl->output(); # and test.tmpl. <!-- TMPL_LOOP NAME=Loop1 --> <!-- TMPL_LOOP NAME=Loop2 --> <!--TMPL_VAR NAME = name --> <!--/TMPL_LOOP --> <!--/TMPL_LOOP -->
    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: TMPL_LOOP inside another TMPL_LOOP with HTML::Template
by borisz (Canon) on Nov 17, 2005 at 09:29 UTC
    Yes. Loops inside another loop is no problem for H:T.
    Boris
Re: TMPL_LOOP inside another TMPL_LOOP with HTML::Template
by saberworks (Curate) on Nov 17, 2005 at 17:06 UTC
    If you are wanting to loop over something in a completely separate array on each iteration of another array, you will need to enable globals. HTML::Template otherwise masks external variables from the guts of each <TMPL_LOOP>. We have run into problems with this if the variables use the same names or even the same keys, so be careful. You can turn on globals with an option passed into the new() method: global_vars => 1