[cgiapp] Adding Footer to Output
Rhesa Rozendaal
perl at rhesa.com
Wed Jan 2 09:52:14 EST 2008
adam at spatialsystems.org wrote:
> I'm adding a footer and I'm using HTML::Template. I'll be including a generic footer using TMPL_INCLUDE and pass the current year to the included footer for the copyright date.
>
> What's the best way to send this info without having to explicitly sending a TMPL_VAR for the year each time? I'd like this to be automatic.
You can do this with a callback to 'load_tmpl':
sub my_load_tmpl_callback {
my ($self, $ht_params, $tmpl_params, $tmpl_file) = @_;
$tmpl_params->{YEAR} ||= current_year();
}
Setting up the callback can be done at several points, but I'd suggest doing
it inside setup() for simplicity:
sub setup {
my $self = shift;
# other setup stuff
# ...
# set default params
$self->add_callback('load_tmpl',\&my_load_tmpl_callback);
}
Refer to the CGI::Application docs for more information on callbacks.
HTH,
Rhesa
More information about the cgiapp
mailing list