1 package Maypole::View::TT;
2 use base 'Maypole::View::Base';
3 use Maypole::Constants;
5 use File::Spec::Functions qw(catdir tmpdir);
8 our $VERSION = "1." . sprintf "%04d", q$Rev$ =~ /: (\d+)/;
11 my ( $self, $r ) = @_;
13 unless ($self->{tt}) {
14 my $view_options = $r->config->view_options || {};
15 (my $driver_name = ref $r) =~ s/::/_/g;
16 my $compile_dir = catdir(tmpdir(), $driver_name);
17 $self->{provider} = Template::Provider->new(
18 COMPILE_DIR => $compile_dir,
21 $self->{tt} = Template->new({
22 COMPILE_DIR => $compile_dir,
24 LOAD_TEMPLATES => [ $self->{provider} ],
28 $self->{provider}->include_path([ $self->paths($r) ]);
31 if ($self->{tt}->process( $r->template, { $self->vars($r) }, \$output )) {
32 $r->{output} = $output;
36 $r->{error} = $self->{tt}->error;
45 Maypole::View::TT - A Template Toolkit view class for Maypole
49 BeerDB->config->view("Maypole::View::TT"); # The default anyway
51 # Set some Template Toolkit options
52 BeerDB->config->view_options( {
54 COMPILE_DIR => '/var/tmp/mysite/templates',
59 This is the default view class for Maypole; it uses the Template Toolkit
60 to fill in templates with the objects produced by Maypole's model classes.
61 Please see the Maypole manual, and in particular, the C<View> chapter,
62 for the template variables available and for a refresher on how template
63 components are resolved.
65 The underlying Template toolkit object is configured through
66 C<$r-E<gt>config-E<gt>view_options>. See L<Template> for available options.
72 Processes the template and sets the output. See L<Maypole::View::Base>