Thanks hippo.
Based on your code sample and what I already have, I have built a test which shows it is not the way I am using Template that is the issue - it is my display() function. In the 'real' code this is abstracted into a Site::HTML module because I want to hide the site variables away in a separate module with only Site::HTML and Site::Common having access to it - perhaps I need to rethink that design.
use Template;
use strict;
my $template = Template->new;
my $vars = {
'frames' => \&get_frames
};
$template->process('test.tt', $vars); # this works
display('test', $vars); # this doesn't
sub get_frames {
my @list;
foreach my $l( qw/first second/ ) {
my $fr = {
'one' => $l,
'two' => $l,
};
push @list, $fr;
}
return @list;
}
sub display {
# my $self = shift;
my $file = shift;
my %vars = @_;
$template->process("$file.tt", \%vars);
}
update
The test Template...
Start test...
[% FOREACH frame IN frames() %]
Frame - [% frame.one %] [% frame.two %]
[% END %]
End test...
|