]> git.decadent.org.uk Git - maypole.git/blob - lib/Maypole/View/TT.pm
+ Updated manual, thanks to Dave Howorth
[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     unless ($self->{tt}) {
14         my $view_options = $r->config->view_options || {};
15         $self->{provider} = Template::Provider->new($view_options);
16         $self->{tt}       = Template->new({
17             %$view_options,
18             LOAD_TEMPLATES => [ $self->{provider} ],
19         });
20     }
21
22     $self->{provider}->include_path([ $self->paths($r) ]);
23
24     my $output;
25     if ($self->{tt}->process( $r->template, { $self->vars($r) }, \$output )) {
26         $r->{output} = $output;
27         return OK;
28     }
29     else {
30         $r->{error} = $self->{tt}->error;
31         return ERROR;
32     }
33 }
34
35 1;
36
37 =head1 NAME
38
39 Maypole::View::TT - A Template Toolkit view class for Maypole
40
41 =head1 SYNOPSIS
42
43     BeerDB->config->view("Maypole::View::TT"); # The default anyway
44
45     # Set some Template Toolkit options
46     BeerDB->config->view_options( {
47         TRIM        => 1,
48         COMPILE_DIR => '/var/tmp/mysite/templates',
49     } );
50
51 =head1 DESCRIPTION
52
53 This is the default view class for Maypole; it uses the Template Toolkit to
54 fill in templates with the objects produced by Maypole's model classes.  Please
55 see the Maypole manual, and in particular, the L<view|Maypole::Manual::View>
56 chapter for the template variables available and for a refresher on how
57 template components are resolved.
58
59 The underlying Template toolkit object is configured through
60 C<$r-E<gt>config-E<gt>view_options>. See L<Template|Template> for available
61 options.
62
63 =over 4
64
65 =item template
66
67 Processes the template and sets the output. See L<Maypole::View::Base>
68
69 =back
70
71
72 =head1 AUTHOR
73
74 Simon Cozens
75
76 =cut
77