Catalyst TT WRAPPER trick
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.
have fun.
Refer: Code in GoogleCode
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.pmhave fun.
Refer: Code in GoogleCode
