01 November 2006
This post may be outdated due to it was written on 2006. The links may be broken. The code may be not working anymore. Leave comments if needed.
Catalyst::View::TT has two different ways:
one is set a $c->stash->{template} then $c->forward($c->view)
the other is using $c->view('TT')->render
so if u want to have a hack on View::TT. better hack on 'sub render' since 'sub process' is calling 'sub render' indeed.

assuimg that we have a very common situation. we have a wrapper.html for whole site. but we don't want to apply the wrapper.html in email body templates and /admin pages.
according to this, we might have two solution.
one is to create two view modulues like TT.pm and NoWrapperTT.pm. config the WRAPPER.
the other is to do some trick on 'sub render' as what I did today.
sub render {
my $self = shift;
my ( $c, $template, $args ) = @_;

# view Catalyst::View::TT for more details
my $vars = {
(ref $args eq 'HASH' ? %$args : %{ $c->stash() }),
};

if ($vars->{no_wrapper}) {
$self->template->service->{WRAPPER} = [];
} else {
$self->template->service->{WRAPPER} = ['wrapper.html'];
}

$self->NEXT::render(@_);
}
so that u can use something like:
my $email_body= $c->view('TT')->render($c, 'email/example.html', {
no_wrapper => 1,
another_var => $another_var,
} );
or set $c->stash->{no_wrapper} = 1 in Admin.pm

have fun.
Refer: Code in GoogleCode


blog comments powered by Disqus