my $config = {
EVAL_PERL => 0,
TEMPLATE_EXTENSION => '',
+ CLASS => 'Template',
%{ $class->config },
%{$arguments},
};
}
$self->{template} =
- Template->new($config) || do {
- my $error = Template->error();
+ $config->{CLASS}->new($config) || do {
+ my $error = $config->{CLASS}->error();
$c->log->error($error);
$c->error($error);
return undef;
This can prove useful when you want to use the additional_template_paths hack
in your own provider, or if you need to use Template::Provider::Encoding
+=head2 C<CLASS>
+
+Allows you to specify a custom class to use as the template class instead of
+L<Template>.
+
+ package MyApp::View::Web;
+
+ use strict;
+ use base 'Catalyst::View::TT';
+
+ use Template::AutoFilter;
+
+ __PACKAGE__->config({
+ CLASS => 'Template::AutoFilter',
+ });
+
+This is useful if you want to use your own subclasses of L<Template>, so you
+can, for example, prevent XSS by automatically filtering all output through
+C<| html>.
+
=head2 HELPERS
The L<Catalyst::Helper::View::TT> and
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+
+my $view = 'Classconfig';
+
+my $response;
+ok(($response = request("/test?view=$view"))->is_success, 'request ok');
+is($response->content, TestApp->config->{default_message}, 'message ok');
+
+my $message = scalar localtime;
+ok(($response = request("/test?view=$view&message=$message"))->is_success, 'request with message ok');
+is($response->content, $message, 'message ok')
--- /dev/null
+use strict;\r
+use warnings;\r
+\r
+package TestApp::Template::Any;\r
+\r
+use base 'Template';\r
+use FindBin;\r
+use Path::Class;\r
+\r
+sub new {\r
+ my $class = shift;\r
+\r
+ my $params = defined($_[0]) && ref($_[0]) eq 'HASH' ? shift : {@_};\r
+\r
+ my $includepath = dir($FindBin::Bin, '/lib/TestApp/root/any_include_path');\r
+ $params->{INCLUDE_PATH} = $includepath;\r
+\r
+ return $class->SUPER::new( $params );\r
+}\r
+\r
+1;\r
--- /dev/null
+package TestApp::View::TT::Classconfig;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+use TestApp::Template::Any;
+
+__PACKAGE__->config(
+ CLASS => 'TestApp::Template::Any',
+);
+
+1;
--- /dev/null
+[% message %]
\ No newline at end of file