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

Is there any documentation on this issue somewhere?
  • Comment on Re^2: IF in a loop using HTML::Template

Replies are listed 'Best First'.
Re^3: IF in a loop using HTML::Template
by kielstirling (Scribe) on Mar 20, 2013 at 20:48 UTC
    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
      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!
      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>.