When creating the site template object
($t = Template->new), the PRE_PROCESS variable gets set to provide config info to every template, and the WRAPPER variable gets tied to my page layout file. It is this meaning of WRAPPER I was thinking of when I spoke of the "site wrapper." My concern is that since the WRAPPER layout file is set at the time of instantiation of the template object I'm not aware of a way of overriding it later on. Come to think of it, I'd also want to be albe to override the PRE_PROCESS variable in the same way.
Dennis,
I think there is an ideological mistake in your message. How do you want
to override PRE_PROCESS from template, if pre-processing takes place before
processing of your template? In other words, when your template has a chance to
change value of PRE_PROCESS variable, the value was already used by TT, so
changing it will have no effect.
But fortunately the WRAPPER action takes place after processing template,
and it seems possible to override WRAPPER directive quite easily. As I have seen
from source code (v 2.14), you should use something like
this:
my $wrappers = [ 'my_default_wrapper.tt' ];
my $template = Template->new({
WRAPPER => $wrappers,
my $template = Template->new({
WRAPPER => $wrappers,
# pass an array ref
(!)
};
$template->process('foo', {
wrapper_array => $wrappers,
};
$template->process('foo', {
wrapper_array => $wrappers,
# pass THE SAME array ref as a variable to
template
});
});
Now you can change WRAPPER array from within your
template:
[%
# replace outer wrapper
wrapper_array.0 = 'some_other_wrapper.tt';
%]
# replace outer wrapper
wrapper_array.0 = 'some_other_wrapper.tt';
%]
or
[%
# add inner wrapper
wrapper_array.push( 'additional_wrapper.tt' );
%]
# add inner wrapper
wrapper_array.push( 'additional_wrapper.tt' );
%]
I have not tested this, but I belive this should work, at least for TT
v.2.14. I'm not sure it is a good idea to relay on such behavior, because it is
not documented and may probably change in future versions. On the other hand, I
don't think it will ever change - maybe only in TT3 :)
--
Sergey
Martynoff
