[Catalyst] Context sensitive template locations
Zbigniew Lukasiak
zzbbyy at gmail.com
Fri Nov 25 12:08:57 CET 2005
Below is my version with an 'unshift_paths' function for adding
additional paths by controllers.
package My::App::View::TT;
use strict;
use base 'Catalyst::View::TT';
use Path::Class;
__PACKAGE__->mk_accessors('include_path');
sub new {
my ($class, $c, $arguments) = @_;
my $root = $c->config->{root};
my $base = Path::Class::dir($root, 'base');
my @include_path = ( "$root", "$base" );
__PACKAGE__->config->{INCLUDE_PATH} = \@include_path;
my $self = $class->SUPER::new($c);
$self->include_path(\@include_path);
return($self);
}
sub unshift_paths {
my($self, @paths) = @_;
unshift(@{$self->include_path}, @paths);
}
1;
Notice that I don't need to subclass the process method.
I would like it to be included in the core Catalyst::View::TT module.
-- Zbyszek
On 11/21/05, Johan Lindström <johanl at darserman.com> wrote:
> At 21:36 2005-11-21, Perrin Harkins wrote:
> >There are lots in the TT archives. I've lost count of the number of
> >times I answered this one.
>
> Yeah, I found a post where you said to look in the archives, but I couldn't
> find any actual code :) The array ref modification it is.
>
>
> New code in case anyone is interested:
>
> -----
> __PACKAGE__->mk_accessors('include_path');
>
> sub new {
> my ($class, $c, $arguments) = @_;
>
> my $root = $c->config->{root};
>
> #Note: Tight coupling with the parent class: Repeat of the
> #default and overridden values
> my $include_path =
> $arguments->{INCLUDE_PATH} ||
> $class->config->{INCLUDE_PATH} ||
> [ $root, "$root/base" ];
> $arguments->{INCLUDE_PATH} = $include_path;
>
> my $self = $class->SUPER::new($c, $arguments);
> $self->include_path($include_path);
>
> return($self);
> }
>
> sub process {
> my ($self, $c) = @_;
>
> my $dir_action = $c->path_to('root', $c->namespace || "base");
>
> unshift(@{$self->include_path}, $dir_action);
> eval { $self->SUPER::process($c); };
> shift(@{$self->include_path});
> $@ and die;
>
> return 1;
> }
> -----
>
> Input welcome.
>
>
> /J
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
More information about the Catalyst
mailing list