Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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
ie,

$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.
-Kiel


Comment on Re: IF in a loop using HTML::Template
Download Code
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.

      HTML::Template
      -Kiel
        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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2014-07-13 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (244 votes), past polls