WebNano::Renderer::TTiny - Dynamic search paths for Template::Tiny
version 0.007
in MyApp.pm:
$self->renderer( WebNano::Renderer::TTiny->new( root => 't/data/templates' ) );
in MyApp::Controller:
return $self->render( template => 'some_template.tt', some_var => 'some_value );
This is a wrapper around Template::Tiny - 'Template Toolkit reimplemented in as little code as possible'.
The only public method here is render - it expects as input a hash with the following data:
The template is then looked for in the directories in INCLUDE_PATH and in directories constructed dynamically from the paths in root and the controller name. For example if 'root' contains [ 'template', 'additional_templates' ] and the controller name is MyApp::Controller::SubController then the template will be looked for in template/SubController and additional_templates/SubController. This mechanism is designed so that it is possible for a way of subclassing templates along with subclassing controllers. If this is too complicated - you can provide no value for the root attribute and use only INCLUDE_PATH.
INCLUDE_PATH
root
[ 'template', 'additional_templates' ]
MyApp::Controller::SubController
template/SubController
additional_templates/SubController
When the template is found - the process method on the internal Template::Tiny object is called. A reference to the whole hash passed to render is passed to the process call - so that all the values are available in the template itself.
process
Template::Tiny
render
If no template name is passed - then it is guessed from the name of the controller method that called render (this is done using caller) and the TEMPLATE_EXTENSION attribute.
TEMPLATE_EXTENSION
Static list of template search directories.
List of directories that are dynamically concatenated with controller names to form a dynamic search list of template directories.
You can use INCLUDE_PATH or root or both.
Postfix added to action name to form the template name ( for example 'edit.tt' from action 'edit' and TEMPLATE_EXTENSION 'tt' ).
Zbigniew Lukasiak <zby@cpan.org>
This software is Copyright (c) 2010 by Zbigniew Lukasiak <zby@cpan.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install WebNano, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WebNano
CPAN shell
perl -MCPAN -e shell install WebNano
For more information on module installation, please visit the detailed CPAN module installation guide.