On 2005-09-13, Wojciech Pietron <suppressed> wrote:
> Hello,
>
> sorry if someone has already mentioned that problem recently. Give me a
> link if it has been already discussed.
>
> There are some variables that I would like to have defined in all templates
> I am going to use, ie. name of the user, url, sysdate etc.
>
> The question is: what is the simplest/best practice to maintain global template
> variables and not redefine them all after loading a new template? I am
> specially interested in CAP::AnyTemplate environment.
Michael Graham and I sketched out a simple plugin for this, but didn't
publish the final proposed API. Or rather, at one point I did prepare
wiki updates for this, but lost them was too frustrated at the time to
re-write them.
I now use a load_tmpl() call back for this. I would like to create a
simple plugin that does the same thing in the future.
In my case I'm passing in all the configuration variables and giving
them the prefix "cfg_".
( This may need the 4.04 development release to work properly...I should just go
ahead and declare that stable. ).
sub cgiapp_init {
$self->add_callback('load_tmpl',\&load_tmpl_callback);
}
sub load_tmpl_callback {
my $self = shift;
my $ht_params = shift;
my $tmpl_params = shift;
my $tmpl_file = shift;
my %CFG = $self->cfg;
# supply global config variables to the templates. Rather than pollute the name space
# let's prefix them with cfg_.
my %new_tmpl_params = (
%prefixed_cfg,
%$tmpl_params
);
for my $key (keys %new_tmpl_params) {
$tmpl_params->{$key} = $new_tmpl_params{$key};
}
}
--
http://mark.stosberg.com/
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.