]> git.decadent.org.uk Git - maypole.git/blob - lib/Maypole/View/TT.pm
+ TT2 objects used in M::V::TT are configurable with
[maypole.git] / lib / Maypole / View / TT.pm
1 package Maypole::View::TT;
2 use base 'Maypole::View::Base';
3 use Maypole::Constants;
4 use Template;
5 use File::Spec::Functions qw(catdir tmpdir);
6
7 use strict;
8 our $VERSION = "1." . sprintf "%04d", q$Rev$ =~ /: (\d+)/;
9
10 sub template {
11     my ( $self, $r ) = @_;
12
13     my $view_options = $r->config->view_options || {};
14     $self->{provider} ||= Template::Provider->new();
15     $self->{tt}       ||= Template->new({
16         COMPILE_DIR    => catdir(tmpdir(), $r->config->application_name),
17         %$view_options,
18         LOAD_TEMPLATES => [ $self->{provider} ],
19     });
20
21     $self->{provider}->include_path([ $self->paths($r) ]);
22
23     my $output;
24     if ($self->{tt}->process( $r->template, { $self->vars($r) }, \$output )) {
25         $r->{output} = $output;
26         return OK;
27     }
28     else {
29         $r->{error} = $self->{tt}->error;
30         return ERROR;
31     }
32 }
33
34 1;
35
36 =head1 NAME
37
38 Maypole::View::TT - A Template Toolkit view class for Maypole
39
40 =head1 SYNOPSIS
41
42     BeerDB->config->view("Maypole::View::TT"); # The default anyway
43
44     # Set some Template Toolkit options
45     BeerDB->config->view_options( {
46         TRIM        => 1,
47         COMPILE_DIR => '/var/tmp/mysite/templates',
48     } );
49
50 =head1 DESCRIPTION
51
52 This is the default view class for Maypole; it uses the Template Toolkit
53 to fill in templates with the objects produced by Maypole's model classes.
54 Please see the Maypole manual, and in particular, the C<View> chapter,
55 for the template variables available and for a refresher on how template
56 components are resolved.
57
58 The underlying Template toolkit object is configured through
59 C<$r-E<gt>config-E<gt>view_options>. See L<Template> for available options.
60
61 =over 4
62
63 =item template
64
65 Processes the template and sets the output. See L<Maypole::View::Base>
66
67 =back
68
69
70 =head1 AUTHOR
71
72 Simon Cozens
73
74 =cut
75