Revision history for Perl extension Catalyst::View::TT.
+0.41 TBA
+ - New local attribute to let you override the default content type when
+ no content type has been set for the response.
0.40 2013-01-15 20:52:14
- Fix hash randomisation breakage in tests (RT#82703)
__PACKAGE__->mk_accessors('template');
__PACKAGE__->mk_accessors('expose_methods');
__PACKAGE__->mk_accessors('include_path');
+__PACKAGE__->mk_accessors('content_type');
*paths = \&include_path;
}
unless ( $c->response->content_type ) {
- $c->response->content_type('text/html; charset=utf-8');
+ my $default = $self->content_type || 'text/html; charset=utf-8';
+ $c->response->content_type($default);
}
$c->response->body($output);
[% uri_for_css('home.css') %]
+=head2 content_type
+
+This lets you override the default content type for the response. If you do
+not set this and if you do not set the content type in your controllers, the
+default is C<text/html; charset=utf-8>.
+
+Use this if you are creating alternative view responses, such as text or JSON
+and want a global setting.
+
+Any content type set in your controllers before calling this view are respected
+and have priority.
+
=head2 C<CATALYST_VAR>
Allows you to change the name of the Catalyst context object. If set, it will also
--- /dev/null
+use strict;
+use warnings;
+use Test::More;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+use_ok('Catalyst::Test', 'TestApp');
+is(request("/test_alt_content_type")->header('Content-Type'), 'text/plain');
+
+done_testing;
$c->stash->{template} = 'test.tt';
}
+sub test_alt_content_type : Local {
+ my ($self, $c) = @_;
+ $c->stash( message => 'test_alt_content_type');
+ $c->forward('View::TT::AltContentType');
+}
+
sub end : Private {
my ($self, $c) = @_;
--- /dev/null
+package TestApp::View::TT::AltContentType;
+
+use strict;
+use base 'Catalyst::View::TT';
+
+__PACKAGE__->config(
+ TEMPLATE_EXTENSION => '.tt',
+ content_type => 'text/plain',
+);