Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: IF in a loop using HTML::Template

by kielstirling (Scribe)
on Mar 20, 2013 at 19:58 UTC ( #1024608=note: print w/replies, xml ) Need Help??

in reply to IF in a loop using HTML::Template

In your template when you look for the param 'test' you are in the data loop.
tmpl_loops take a arrayref of hashref
$tmpl->param(data=>[{test=>1, foo=>1, bar=>1}]);
My understanding is that you can't refer to params outside of the loop. Like you are doing with the test param.

Replies are listed 'Best First'.
Re^2: IF in a loop using HTML::Template
by Anonymous Monk on Mar 20, 2013 at 20:35 UTC
    Is there any documentation on this issue somewhere?
      From the POD ...

      Inside a <TMPL_LOOP>, the only variables that are usable are the ones from the <TMPL_LOOP>. The variables in the outer blocks are not visible within a template loop. For the computer-science geeks among you, a <TMPL_LOOP> introduces a new scope much like a perl subroutine call. If you want your variables to be global you can use global_vars option to new() described below.

        Thank you all, now back to the drawing board!
        I meant that because I'm using this logic with CGI::Application, I need to research on the global variable case since it will be in a subroutine as in my first sample code posted earlier.
        I found what I needed based on information from you, by adding this line: "global_vars=1" - It treats parameters sent to the template as global.
        my $t=HTML::Template->new(filename=>'temp.tmpl', global_vars => 1,);
        Thanks again for pointing me to the right direction!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024608]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-04-19 22:01 GMT
Find Nodes?
    Voting Booth?