The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Daizu::TTProvider - fetch TT templates from a Daizu working copy

DESCRIPTION

This is a subclass of Template::Provider which overrides the normal way in which templates are loaded. It loads templates from the database, and searches for them in directories determined by the path of the file being published. So for example, there can be templates in various _template directories at various points in the working copy file hierarchy, so each website can have its own set of templates which override the default ones, and subsections can have extra templates, and so on.

This module is used in the generate_web_page method in Daizu::Gen.

If a template can't be found in the working copy _template directories, then it is looked for among the templates distributed with Daizu. Thus these templates provide a default site look-and-feel, while they can be overridden by adding templates to the repository.

TODO - currently there is a kludge to allow templates whose names are overridden by a generator to include the original version. They can do this by prefixing the name with no-override:, but this feature is likely to be removed and replaced with something better, once I've figure out what that is.

While testing templates it may be easier to edit them as normal files and have this module instead load those, so that you don't have to do a commit and a working copy update after every experimental change. To make this happen, add something like the following to your Daizu CMS configuration file:

    <template-test path="/home/geoff/svn/web_geoff" />

USING FROM CODE

This example shows how to do Template Toolkit processing with templates loaded from a Daizu working copy. It is intended to generate the file in $file using template $template_name. This example is derived from code in Daizu::Gen.

    use Daizu::TTProvider;

    my $provider = Daizu::TTProvider->new({
        daizu_cms => $cms,
        daizu_wc_id => $file->{wc_id},
        daizu_file_path => $file->directory_path,
        daizu_template_overrides => $template_overrides,
    });

    my $tt = Template->new({
        LOAD_TEMPLATES => $provider,
    }) or die $Template::ERROR;

    $tt->process($template_name, \%vars, $fh)
        or die $Template::ERROR;

The option daizu_template_overrides can be undef or a reference to a hash of rewriting instructions. Each key is the name of a template, including its relative path. If that template is loaded, this module will in fact load the template specified in the corresponding value. This mechanism is used by subclasses of Daizu::Gen to customize presentation without the user having to put override templates in their repository. In effect, it provides an additional way of overriding which templates are used, which is orthogonal to the _template directories in working copies.

METHODS

$provider->fetch($name)

Return a list of two values: the data for the named template and an error code. The second value will be true if there was an error.

COPYRIGHT

This software is copyright 2006 Geoff Richards <geoff@laxan.com>. For licensing information see this page:

http://www.daizucms.org/license/