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