Dancer::Template::Handlebars - Wrapper for the Handlebars template system
version 0.2.2
# in config.yml template: handlebars engines: handlebars: helper_modules: - MyApp::HandlebarsHelpers # in the app get '/style/:style' => sub { template 'style' => { style => param('style') }; }; # in views/style.mustache That's a nice, manly {{style}} mustache you have there!
Wrapper for Text::Handlebars, the Perl implementation of the Handlebars templating system.
The arguments passed to the 'handlebars' engine are given directly to the Text::Handlebars constructor, with the exception of helper_modules (see below for details).
helper_modules
When calling template, one can use a filename as usual, or can pass a string reference, which will treated as the template itself.
template
get '/file' => sub { # look for the file views/my_template.hbs template 'my_template', { name => 'Bob', }; }; get '/string' => sub { # provide the template directly template \'hello there {{name}}', { name => 'Bob', }; };
The default extension for Handlebars templates is 'hbs'.
hbs
Handlebars helper functions can be defined in modules, which are passed via helper_modules in the configuration. See Dancer::Template::Handlebars::Helpers for more details on how to register the functions themselves.
Layouts are supported. The content of the inner template will be available via the 'content' variable.
Example of a perfectly valid, if slightly boring, layout:
<html> <body> {{ content }} </body> </html>
Yanick Champoux <yanick@babyl.dyndns.org>
This software is copyright (c) 2014 by Yanick Champoux.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dancer::Template::Handlebars, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Template::Handlebars
CPAN shell
perl -MCPAN -e shell install Dancer::Template::Handlebars
For more information on module installation, please visit the detailed CPAN module installation guide.