Dennis wrote concernedly:
> 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.
That's right. But you can have that master WRAPPER template delegate to
further wrapper(s) of your choice, based on whatever kind of logic you
care to implement.
Here's an example of how I typically do it (essentially the same thing as in
the Badger Book). I use a PRE_PROCESS template to generate a page metadata
structure which includes a 'type' flag.
config/main:
[% page = {
type = template.type or 'html'
# ...etc...
}
%]
Each page can set its type using a META tag (which is evaluated when the
template is parsed and can only contain static values):
[% META type='text' %]
Or by poking the page data structure (which happens at template runtime and
can contain an expression or other dynamic values):
[% page.type = some_test ? 'html' : 'text' %]
Then the master wrapper template applies the appropriate custom wrappers
for each page, depending on page.type
site/wrapper:
[% SWITCH page.type;
CASE 'text';
content;
CASE 'html';
content WRAPPER site/html
+ site/layout;
CASE;
THROW page.type "Invalid page type: $page.type";
END;
-%]
So my Template config looks something like this:
my $tt = Template->new({
PRE_PROCESS => 'config/main',
WRAPPER => 'site/wrapper',
# ...etc...
});
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates