I tend to declare WRAPPER
in each main template directly, rather than globally like that.
[%- WRAPPER c.req.uri.host _ '/site/wrapper.tt'; -%]
... as I find it allows for far more flexibility.
However...
Another option that I have had great success with is using a custom template path, so that domain specific versions of your templates can over-ride defaults, where they exist. This gives you enormous flexibility to inject variations of your code as required.
=== MyApp::View::TT.pm ===
sub process {
my ($self, $c) = @_;
# capture original path, identify host
my @orig_include_path = @{$self->include_path};
my $domain = $c->req->uri->host;
# augment every path with domain/path
@{$self->include_path} = map { ("$domain/$_", $_) } @orig_include_path;
$self->SUPER::process($c);
# revert path
@{$self->include_path} = @orig_include_path;
}
The net result of which is that every call for a WRAPPER
, a PROCESS
or an INCLUDE
will check for a domain specific version or produce the generic version, i.e.
[%- WRAPPER wrapper.tt -%]
will find $domain/wrapper.tt
or fall back to wrapper.tt
if there's no such file. This automatically extends to:
- foo/bar/baz.tt
- domain1/foo/bar/baz.tt
- domain2/foo/bar/baz.tt
Hope that's useful.