Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: IF in a loop using HTML::Template

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


in reply to Re^2: IF in a loop using HTML::Template
in thread IF in a loop using HTML::Template

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


Comment on Re^3: IF in a loop using HTML::Template
Re^4: IF in a loop using HTML::Template
by Anonymous Monk on Mar 20, 2013 at 21:40 UTC
    Thank you all, now back to the drawing board!
      You don't need to go back to the drawing board, just set the global_vars option as quoted above:
      If you want your variables to be global you can use global_vars option to new() described below.
      From the docs:
      global_vars - normally variables declared outside a loop are not available inside a loop. This option makes <TMPL_VAR>s like global variables in Perl - they have unlimited scope. This option also affects <TMPL_IF> and <TMPL_UNLESS>.
Re^4: IF in a loop using HTML::Template
by Anonymous Monk on Mar 21, 2013 at 01:54 UTC
    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.
Re^4: IF in a loop using HTML::Template
by Anonymous Monk on Mar 21, 2013 at 12:40 UTC
    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://1024616]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2014-09-03 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls