Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

TMPL_LOOP inside another TMPL_LOOP with HTML::Template

by jesuashok (Curate)
on Nov 17, 2005 at 09:11 UTC ( #509339=perlquestion: print w/ replies, xml ) Need Help??
jesuashok has asked for the wisdom of the Perl Monks concerning the following question:

Hi

If any one Worked in HTML::Template effectively module Please give me your thoughts.

Is there a way to use TMPL_LOOP inside another TMPL_LOOP Example

<TMPL_LOOP> <TMPL_LOOP> </TMPL_LOOP> </TMPL_LOOP>


Thanx in advance

"Keep pouring your ideas"

Comment on TMPL_LOOP inside another TMPL_LOOP with HTML::Template
Download Code
Re: TMPL_LOOP inside another TMPL_LOOP with HTML::Template
by marto (Chancellor) 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 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 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 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://509339]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-07-25 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls