Dancer2::Template::Haml - Text::Haml template engine wrapper for Dancer2
To use this engine, you may configure Dancer2 via config.yaml:
config.yaml
template: "haml" engines: template: haml: cache: 1 cache_dir: "./.text_haml_cache"
Or you may also change the rendering engine by setting it manually with set keyword:
set
set template => 'haml'; set engines => { template => { Haml => { cache => 1, cache_dir => './.text_haml_cache' }, }, };
Example:
views/index.haml:
views/index.haml
%h1= $foo
views/layouts/main.haml:
views/layouts/main.haml
!!! 5 %html %head %meta(charset = $settings->{charset}) %title= $settings->{appname} %body %div(style="color: green")= $content #footer Powered by %a(href="https://metacpan.org/release/Dancer2") Dancer #{$dancer_version}
A Dancer 2 application:
use Dancer2; get '/' => sub { template 'index' => {foo => 'Bar!'}; };
This is an interface between Dancer2's template engine abstraction layer and the Text::Haml module.
Based on the Dancer2::Template::Xslate and Dancer::Template::Haml modules.
You can use templates and layouts defined in __DATA__ section:
use Dancer2; use Data::Section::Simple qw/get_data_section/; my $vpath = get_data_section; set layout => 'main'; set appname => "Dancer2::With::Haml"; set charset => "UTF-8"; set template => 'haml'; set engines => { template => { Haml => { cache => 1, cache_dir => './.text_haml_cache', path => $vpath, }, }, }; get '/bazinga' => sub { template 'bazinga' => { text => 'Bazinga?', foo => 'Bar!', }; }; true; __DATA__ @@ layouts/main.haml !!! 5 %html %head %meta(charset = $settings->{charset}) %title= $settings->{appname} %body %div(style="color: green")= $content #footer Powered by %a(href="https://metacpan.org/release/Dancer2") Dancer #{$dancer_version} @@ bazinga.haml %strong= $text %p= $foo %em text 2 texts 3
Haml rendering engine for Dancer 1.
Haml Perl implementation
https://github.com/TheAthlete/Dancer2-Template-Haml
Viacheslav Koval, <athlete AT cpan DOT org>
Copyright © 2013 by Viacheslav Koval.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Dancer2::Template::Haml, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer2::Template::Haml
CPAN shell
perl -MCPAN -e shell install Dancer2::Template::Haml
For more information on module installation, please visit the detailed CPAN module installation guide.