[Catalyst] dynamic include path for tt

Bill Moseley moseley at hank.org
Fri Nov 4 07:07:54 CET 2005


On Fri, Nov 04, 2005 at 04:16:13PM +1100, Ben Norman wrote:
> >I often just keep the template path array ref around as class data:
> >
> >   __PACKAGE__->config->{INCLUDE_PATH} = \@template_path;
> >
> >Then in process (or somewhere that has access to @template_path)
> >adjust @template_path as needed.

> Does that mean I dont need the new sub in the TT component anymore?
> Can you post an example?

You didn't say "working" example, so I can post off the top of my head
and you can hopefully make it work.

Maybe something like:


package App::V::TT;

use strict;
use base 'Catalyst::View::TT';

our @template_path; # or mk_classdata perhaps
our $default_path = App->config->{root} . '/' . ( App->config->{TT}{include} || 'tt' );


__PACKAGE__->config->{INCLUDE_PATH} = \@template_path;
__PACKAGE__->config->{WRAPPER}      = 'page/wrapper.tt';
__PACKAGE__->config->{PRE_PROCESS}  = 'config.tt';

sub process {
    my $self = shift;
    my $c = $_[0];
    @template_path = ( $c->stash->{include_dir}, $default_path );
    $self->SUPER::process(@_);
}

1;

-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list