in reply to Re: Preparing data for Template
in thread Preparing data for Template
It won't get called unless you call it ;-)
I was kind of assuming that the Template code calls the subroutine at some point! After all, it gets passed the reference...
In the example code, get_user_projects doesn't seem to be explicitly called.
#!/usr/bin/perl use strict; use warnings; use Template; use CGI; $| = 1; print "Content-type: text/html\n\n"; my $file = 'userinfo.html'; my $vars = { 'version' => 3.14, 'days' => [ qw( mon tue wed thu fri sat sun ) ], 'worklist' => \&get_user_projects, 'cgi' => CGI->new(), 'me' => { 'id' => 'abw', 'name' => 'Andy Wardley', }, }; sub get_user_projects { my $user = shift; my @projects = ... # do something to retrieve data return \@projects; } my $template = Template->new({ INCLUDE_PATH => '/home/abw/websrc/src:/home/abw/websrc/lib', PRE_PROCESS => 'config', }); $template->process($file, $vars) || die $template->error();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Preparing data for Template
by pryrt (Abbot) on Dec 31, 2020 at 00:51 UTC | |
by Bod (Parson) on Dec 31, 2020 at 11:05 UTC | |
by hippo (Archbishop) on Dec 31, 2020 at 11:47 UTC | |
by Bod (Parson) on Dec 31, 2020 at 12:41 UTC | |
by Corion (Patriarch) on Dec 31, 2020 at 12:48 UTC | |
| |
by GrandFather (Saint) on Jan 01, 2021 at 09:14 UTC | |
by Bod (Parson) on Jan 01, 2021 at 13:48 UTC |