Menu

#2 global_vars fails for tmpl_includes under tmpl_loop

open
nobody
None
5
2006-09-22
2006-09-22
potatono
No

When using a TMPL_INCLUDE inside a TMPL_LOOP the
global_vars are not included.

Here's an example:

test.pl
-------
use strict;
use HTML::Template::Compiled speed=>1;

my $htc = new HTML::Template::Compiled(
filename => 'index.tmpl',
global_vars => 1
);

$htc->param({
foo => 'foo',
bar => [
{ baz => 'baz' },
{ baz => 'baz' }
]
});

print $htc->output();

index.tmpl
----------
This is the top level template...

FOO = <TMPL_VAR name='foo'>

Start of loop
<TMPL_LOOP name='bar'>
Loop iteration
FOO = <TMPL_VAR name='foo'>
<TMPL_INCLUDE name='include.tmpl'>
</TMPL_LOOP>
End of loop

<TMPL_INCLUDE name='include.tmpl'>

End top level template.

include.tmpl
------------
Start include template
BAZ = <TMPL_VAR name='baz'>
FOO = <TMPL_VAR name='foo'>
End include template

OUTPUT
------
This is the top level template...

FOO = foo

Start of loop

Loop iteration
FOO = foo
Start include template
BAZ = baz
FOO =
End include template

Loop iteration
FOO = foo
Start include template
BAZ = baz
FOO =
End include template

End of loop

Start include template
BAZ =
FOO = foo
End include template

End top level template.

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.