Dancer
view release on metacpan or search on metacpan
lib/Dancer/Template/TemplateToolkit.pm view on Meta::CPAN
engines:
template_toolkit:
COMPILE_DIR: 'caches/templates'
COMPILE_EXT: '.ttc'
Note though that unless you change them, Dancer sets both of the Template
options C<ANYCASE> and C<ABSOLUTE> on, as well as pointing C<INCLUDE_PATH>
to your B<views> directory and setting C<ENCODING> to your B<charset>
setting.
=head1 SUBCLASSING
By default, L<Template> is used, but you can configure Dancer to use a
subclass of Template with the C<subclass> option.
engines:
template_toolkit:
subclass: My::Template
When used like this, Dancer skips the defaults mentioned above. Only those
included in your config file are sent to the subclass.
=head1 WRAPPER, META variables, SETs
Dancer already provides a WRAPPER-like ability, which we call a "layout". The
reason we do not use TT's WRAPPER (which also makes it incompatible with it) is
because not all template systems support it. Actually, most don't.
However, you might want to use it, and be able to define META variables and
regular L<Template::Toolkit> variables.
These few steps will get you there:
=over 4
=item * Disable the layout in Dancer
You can do this by simply commenting (or removing) the C<layout> configuration
in the F<config.yml> file.
=item * Use Template Toolkit template engine
Change the configuration of the template to Template Toolkit:
# in config.yml
template: "template_toolkit"
=item * Tell the Template Toolkit engine who's your wrapper
# in config.yml
# ...
engines:
template_toolkit:
WRAPPER: layouts/main.tt
=back
Done! Everything will work fine out of the box, including variables and META
variables.
=head1 EMBEDDED TEMPLATES
You can embed your templates in your script file, to get a self-contained dancer
application in one file (inspired by L<http://advent.perldancer.org/2011/3>).
To enable this:
# in app.pl
# ...
set engines => {
template_toolkit => {
embedded_templates => 1,
},
};
set template => 'template_toolkit';
This feature requires L<Template::Provider::FromDATA>. Put your templates in the
__DATA__ section, and start every template with __${templatename}__.
=head1 USING TT'S WRAPPER STACK
This engine provides three additional methods to access the WRAPPER stack of
TemplateToolkit.
=head2 set_wrapper
Synopsis:
engine('template')->set_wrapper( inner => 'inner_layout.tt' );
engine('template')->set_wrapper( outer => 'outer_layout.tt' );
engine('template')->set_wrapper( 'only_layout.tt' );
The first two lines pushes/unshifts layout files to the wrapper array.
The third line overwrites the wrapper array with a single element.
=head2 unset_wrapper
Synopsis:
engine('template')->unset_wrapper('inner') # returns 'inner_layout.tt';
engine('template')->unset_wrapper('outer') # returns 'outer_layout.tt';
These lines pops/shifts layout files from the wrapper array and returns the
removed elements.
=head2 reset_wrapper
Synopsis:
engine('template')->reset_wrapper;
This method restores the wrapper array after a set_wrapper call.
=head1 SEE ALSO
L<Dancer>, L<Template>
=head1 AUTHOR
Dancer Core Developers
( run in 1.095 second using v1.01-cache-2.11-cpan-71847e10f99 )