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

Replies are listed 'Best First'.
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!