NAME

Catalyst::View::TT - Template View Class

SYNOPSIS

# use the helper
myapp_create.pl view TT TT

# lib/MyApp/View/TT.pm
package MyApp::View::TT;

use base 'Catalyst::View::TT';

__PACKAGE__->config->{DEBUG} = 'all';

# in practice you'd probably set this from a config file;
# defaults to $c->config->root
__PACKAGE__->config->{INCLUDE_PATH} =
   '/usr/local/generic/templates:/usr/local/myapp/templates';

1;

# Meanwhile, maybe in a private C<end> action
$c->forward('MyApp::View::TT');

DESCRIPTION

This is the Catalyst view class for the Template Toolkit. Your application subclass should inherit from this class. This plugin renders the template specified in $c->stash->{template}, or failing that, $c->request->match. The template variables are set up from the contents of $c->stash, augmented with template variable base set to Catalyst's $c->req->base, template variable c to Catalyst's $c, and template variable name to Catalyst's $c->config->{name}. The output is stored in $c->response->output.

If you want to override TT config settings, you can do it in your application's view class by setting __PACKAGE__->config->{OPTION}, as shown in the Synopsis. Of interest might be EVAL_PERL, which is disabled by default, INCLUDE_PATH, and LOAD_TEMPLATES, which is set to use the provider.

If you want to use EVAL_PERL, add something like this:

__PACKAGE__->config->{EVAL_PERL} = 1;
__PACKAGE__->config->{LOAD_TEMPLATES} = undef;

If you have configured Catalyst for debug output, Catalyst::View::TT will enable profiling of template processing (using Template::Timer). This will embed HTML comments in the output from your templates, such as:

<!-- TIMER START: process mainmenu/mainmenu.ttml -->
<!-- TIMER START: include mainmenu/cssindex.tt -->
<!-- TIMER START: process mainmenu/cssindex.tt -->
<!-- TIMER END: process mainmenu/cssindex.tt (0.017279 seconds) -->
<!-- TIMER END: include mainmenu/cssindex.tt (0.017401 seconds) -->

....

<!-- TIMER END: process mainmenu/footer.tt (0.003016 seconds) -->

You can suppress template profiling when debug is enabled by setting:

__PACKAGE__->config->{CONTEXT} = undef;

METHODS

new

The constructor for the TT view. Sets up the template provider, and reads the application config.

process

Renders the template specified in $c->stash->{template} or $c->request->match. Template variables are set up from the contents of $c->stash, augmented with base set to $c->req->base, c to $c and name to $c->config->{name}. Output is stored in $c->response->output.

config

This allows your view subclass to pass additional settings to the TT config hash.

SEE ALSO

Catalyst, Template::Manual

AUTHOR

Sebastian Riedel, sri@cpan.org Marcus Ramberg, mramberg@cpan.org Jesse Sheidlower, jester@panix.com

COPYRIGHT

This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.