Template Toolkit change tags



examples/dancer/template-toolkit-tags/config.yml
---
template: "template_toolkit"
engines:
  template:
    template_toolkit:
      # Note: start_tag and end_tag are regexes
      start_tag: '<%'
      end_tag:   '%>'

examples/dancer/template-toolkit-tags/app.psgi
package App;
use Dancer2;

debug config->{template};

get '/' => sub {
    return template 'main.tt', {
        name => 'Perl Dancer',
        on => 0,
        languages => ['Perl', 'Python', 'Go'],
        perl => {
            creator => 'Larry Wall',
            release => 1987,
        },
        fruits => [
            {
                name => 'Apple',
                color => 'Red',
            },
            {
                name => 'Banana',
                color => 'Yellow',
            },
            {
                name => 'Peach',
                color => 'Peach',
            }
        ],
        template_name => config->{template},
    };
};

App->to_app;

examples/dancer/template-toolkit-tags/views/main.tt
<h1>Hello World</h1>
<h2><% name %></h2>

<% IF on %>
<h2>It is on</h2>
<% ELSE %>
<h2>It is off</h2>
<% END %>

<% IF languages %>
  <h2>Languages</h2>
  <ul>
    <% FOREACH lang IN languages %>
      <li><% lang %></li>
    <% END %>
  </ul>
<% END %>

<h2>Perl</h2>
Creator: <% perl.creator %><br>
Release: <% perl.release %><br>

<h2>Fruits</h2>
<table>
<% FOREACH fruit IN fruits %>
  <tr><td><% fruit.name %></td><td><% fruit.color %></td></tr>
<% END %>
</table>

<hr>
Template <% template_name %>