in reply to Re^5: Preparing data for Template
in thread Preparing data for Template
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...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Preparing data for Template
by Corion (Patriarch) on Dec 31, 2020 at 12:48 UTC | |
by Bod (Parson) on Dec 31, 2020 at 12:57 UTC | |
by haukex (Archbishop) on Dec 31, 2020 at 13:27 UTC | |
by LanX (Saint) on Dec 31, 2020 at 14:34 UTC | |
by Corion (Patriarch) on Dec 31, 2020 at 13:25 UTC |