I try to display an array item in dancer, here is the code:
get '/' => sub {
my @rows = ('aaa','bbb','ccc');
template 'crud.tt', {'rows' => \@rows};
};
and the template is:
<h2><% $rows[1] %></h2>
<h2><% rows[1] %></h2>
<% FOREACH r IN rows %>
<p><% r %></p>
<% END %>
In the h2 element show nothing, what is the right way?
You can’t pass anything but a simple scalar value if you are using the default
Dancertemplate engine. But if you enableTemplate::Toolkitas the engine then all kinds of things are possible.You can do this globally by setting
template: template_toolkitin the YAML config file, or you can set it just for this route by writingYour template will look like
and you will need
to load the
Template::Toolkitmodule before you use either method