bigpresh / dancer-template-htmltemplate Goto Github PK
View Code? Open in Web Editor NEWDancer::Template::HtmlTemplate - HTML::Template wrapper for Dancer
Home Page: http://search.cpan.org/dist/Dancer-Template-HtmlTemplate
Dancer::Template::HtmlTemplate - HTML::Template wrapper for Dancer
Home Page: http://search.cpan.org/dist/Dancer-Template-HtmlTemplate
NAME Dancer::Template::HtmlTemplate - HTML::Template wrapper for Dancer DESCRIPTION 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: HtmlTemplate 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, the default layout `main.tt' generated by the scaffolding script must be updated to use HTML::Template directives: [% content %] needs to be changed to: <!--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 and example templates appropriately. Also, the current default file extension for template files is `.tt'; at the time this template engine wrapper was produced, the template engine wrapper could not override default file extensions. This is now possible, but I haven't made this change as it would break applications relying on the default being `.tt'. If you want to change the extension used, use the `extension' configuration option, for example, to declare that the extension should be `.tmpl': template: HtmlTemplate engines: HtmlTemplate: extension: 'tmpl' WARNING - Even if you use the default `.tt', you may want to explictly set the `extension' setting to indicate that, as future versions may default to a more suitable file extension. Handling nested hashrefs 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: <TMPL_VAR name="session.username"> SEE ALSO Dancer, HTML::Template AUTHOR David Precious, `<[email protected]>' CONTRIBUTING This module is developed on Github at: http://github.com/bigpresh/Dancer-Template-HtmlTemplate Feel free to fork the repo and submit pull requests! ACKNOWLEDGEMENTS Thanks to Damien Krotkine for providing code to flatten nested hashrefs in a way that allows HTML::Template templates to make use of them. LICENSE This module is free software and is released under the same terms as Perl itself.
Based on http://www.backup-manager.org/pipermail/dancer-users/2010-October/000381.html
Response from David:
Rather than hardcoding the param names to look at, I think I'd be inclined to
have it automatically flatten any hashrefs in the params into keys in the to
level hashref of params - so, for instance, if the params that were going to
be passed to HTML::Template looked like:
{
foo => 1,
bar => {
baz => 2,
bletch => 3,
}
}
it would get "flattened" into, say,:
{
foo => 1,
bar.baz => 2,
bar.bletch => 3,
}
Having to do that is nasty, but it's a limitation of HTML::Template which
doesn't let you dig into hashrefs, unlike for instance TT, where you can quite
happily use e.g. [% foo.bar %]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.