1 package Catalyst::View::TT;
4 use base qw/Catalyst::Base Class::Data::Inheritable/;
11 __PACKAGE__->mk_accessors('template');
12 __PACKAGE__->mk_classdata('config');
14 __PACKAGE__->config( { EVAL_PERL => 0 } );
18 Catalyst::View::TT - Template View Class
25 # lib/MyApp/View/TT.pm
26 package MyApp::View::TT;
28 use base 'Catalyst::View::TT';
30 __PACKAGE__->config->{DEBUG} = 'all';
34 $c->forward('MyApp::View::TT');
38 This is the C<Template> view class. Your subclass should inherit
39 from this class. If you want to override TT config settings, you
40 can do it there by setting __PACKAGE__->config->{OPTION} as shown
41 in the synopsis. Of interest might be EVAL_PERL, which is disabled
42 by default, and LOAD_TEMPLATES, which is set to use the provider.
44 If you want to use EVAL perl, add something like this:
46 __PACKAGE__->config->{EVAL_PERL} = 1;
47 __PACKAGE__->config->{LOAD_TEMPLATES} = undef;
49 =head2 OVERLOADED METHODS
56 my $self = $class->NEXT::new(@_);
57 our ($template, $provider);
58 my $root = $c->config->{root};
59 $provider ||= Template::Provider->new();
60 $provider->include_path([ $root, "$root/base" ]);
61 my %config= ( LOAD_TEMPLATES => [ $provider ],
62 %{ $class->config() },
63 INCLUDE_PATH => [ $root, "$root/base" ]
65 $config{CONTEXT} = Template::Timer->new(%config) if $c->debug;
66 $self->template( Template->new(\%config));
72 Renders the template specified in $c->stash->{template} or $c->request->match
73 to $c->response->output.
78 my ( $self, $c ) = @_;
79 $c->res->headers->content_type('text/html;charset=utf8');
81 my $name = $c->stash->{template} || $c->req->match;
83 $c->log->debug('No template specified for rendering') if $c->debug;
86 $c->log->debug(qq/Rendering template "$name"/) if $c->debug;
88 $self->template->process(
92 base => $c->req->base,
94 name => $c->config->{name}
100 my $error = $self->template->error;
101 $error = qq/Couldn't render template "$error"/;
102 $c->log->error($error);
105 $c->res->output($output);
111 This allows your view subclass to pass additional settings to the
122 Sebastian Riedel, C<sri@cpan.org>
127 This program is free software, you can redistribute it and/or modify it under
128 the same terms as Perl itself.