in reply to Re: Re: Re: TMPL_IF
in thread Learning syntax for HTML::Template TMPL_IF
If I understand your question correctly, you're defining an HTML::Template parameter outside a loop and then trying to use it within a TMPL_LOOP. I.e., the code looks something like this:
And your template looks like this:my $template = new HTML::Template ( filename => "file.tmpl" ); $template->param( outside_of_loop => "foo", the_loop => [ { inside_of_loop => "bar" }, { inside_of_loop => "baz" } ] );
You're expecting this output:Outside: <TMPL_VAR NAME=outside_of_loop> <TMPL_LOOP NAME=the_loop> Inside: <TMPL_VAR NAME=outside_of_loop> <TMPL_VAR NAME=inside_of_l +oop> </TMPL_LOOP>
But you're getting this instead:Outside: foo Inside: foo bar Inside: foo baz
The problem is that TMPL_VARs defined outside of a loop don't show up within the loop. The solution is to set global_vars => 1 when you create the HTML::Template object. E.g.:Outside: foo Inside: bar Inside: baz
my $template = new HTML::Template ( filename => "file.tmpl", global_vars => 1 );
-Matt
|
---|
In Section
Seekers of Perl Wisdom