Dancer::Template::HtmlTemplate - HTML::Template wrapper for Dancer
This class is an interface between Dancer's template engine abstraction layer and the HTML::Template module.
In order to use this engine, use the template setting:
template: html_template
This can be done in your config.yml file or directly in your app code with the set keyword.
Since HTML::Template uses different syntax to other template engines like Template::Toolkit, for current Dancer versions the default layout main.tt will need to be updated, changing the [% content %] line to:
[% content %]
<!--tmpl_var name="content"-->
or
<TMPL_VAR name="content">
Future versions of Dancer may ask you which template engine you wish to use, and write the default layout appropriately.
Also, currently template filenames should end with .tt; again, future Dancer versions may change this requirement.
Since HTML::Template does not allow you to access nested hashrefs (at least, not without switching to using HTML::Template::Pluggable along with HTML::Template::Plugin::Dot), this module "flattens" nested hashrefs.
For instance, the session contents are passed to Dancer templates as session - to access a key of that hashref named username, you'd say:
session
username
<TMPL_VAR name="session.username">
Dancer, HTML::Template
David Precious, <davidp@preshweb.co.uk>
<davidp@preshweb.co.uk>
This module is developed on Github at:
http://github.com/bigpresh/Dancer-Template-HtmlTemplate
Feel free to fork the repo and submit pull requests!
Thanks to Damien Krotkine for providing code to flatten nested hashrefs in a way that allows HTML::Template templates to make use of them.
This module is free software and is released under the same terms as Perl itself.
To install Dancer::Template::HtmlTemplate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Template::HtmlTemplate
CPAN shell
perl -MCPAN -e shell install Dancer::Template::HtmlTemplate
For more information on module installation, please visit the detailed CPAN module installation guide.