NAME
Thunderhorse::Module::Template - Template module for Thunderhorse
SYNOPSIS
# in application build method
$self->load_module('Template' => {
paths => ['views'],
conf => {
EVAL_PERL => true,
},
});
# in controller method
sub show_page ($self, $ctx)
{
return $self->template('page', {
title => 'My Page',
content => 'Hello, World!',
});
}
# parse DATA handle
sub render_data ($self, $ctx)
{
return $self->template(\*DATA);
}
DESCRIPTION
The Template module adds template rendering capabilities using Template::Toolkit. It adds a "template" method to controllers.
CONFIGURATION
Configuration is passed to Gears::Template::TT, which wraps Template Toolkit.
conf- hash of Template::Toolkit configuration valuespaths- array ref of paths to search for templatesencoding- encoding of template files, UTF-8 by default
paths and encoding will be automatically set as proper keys in Template::Toolkit config, unless it was specified there separately, in which case they will be ignored.
ADDED INTERFACE
Controller Methods
template
$self->template('page', { title => 'My Page' });
$self->template(\*DATA);
$self->template(\$template_string);
Parses a template and returns the content. The first argument is the template name (.tt suffix will be added automatically), and the second is a hash reference of variables to pass to the template. The method returns the parsed content, which can then be returned from the handler to be sent to the client as HTML (if the context is not already consumed).
If the first argument is passed as a reference, the behavior changes:
for GLOB refs, filehandle will be read and its contents will be used as the template
for SCALAR refs, the referenced scalar will be used as the template
GLOB refs will be rolled back after reading them automatically, making it useful for rendering from DATA handles.