On Mon, Jun 8, 2009 at 10:42 PM, Robert Buels <[email protected]> wrote:
> Matt S Trout wrote:
>
>> Just have your controller base class set:
>>
>> $c->stash(additional_template_paths => $self->template_paths);
>>
>
> Can you do something similar if using Mason?
>
Yes, use multiple comp_roots:
<code>
package MyApp::View::Mason;
use parent 'Catalyst::View::Mason';
__PACKAGE__->config(
comp_root => [
[ foo => '/myapp/root/templates/foo' ],
[ bar => '/myapp/root/templates/bar' ],
],
);
</code>
The comp_roots are treated as a single component tree by the Mason
resolver. If the same template path exists in multiple comp_roots, the one
in the first listed comp_root is used; the later ones are never seen. All
standard Mason mechanics apply to the resulting component tree.
This config syntax, however, can be a pain to include in external config
files, since it's an array of arrays (YAML looks ugly, Config::General can't
even do it at all, the rest I don't know). My hack was to use a COMPONENT
hook to transform a single key/value into whatever I needed. Here's an
example of one I use with a multiple-client app to setup a client-specific
template directory followed by a common template set:
<code>
sub COMPONENT {
my $self = shift;
my($c,$arguments) = @_;
$arguments->{comp_root} ||= [
[ client => $c->path_to('root/template/client',
lc($c->config->{client})) ],
[ base => $c->path_to('root/template/base') ],
];
$self->next::method(@_);
}
</code>
So the above with config:
<MyApp>
client foo
</MyApp>
results in the equivalent of:
<code>
MyApp->config(
comp_root => [
[ client => '/myapp/root/template/client/foo' ],
[ base => '/myapp/root/template/base' ],
],
);
</code>
--
Stephen Clouse <[email protected]>
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/