Question

I have perl generating a list through Template Toolkit.

How do I add a couple of single non-list variables into the mix, e.g. to include outside of the FOREACH within the .tt2 file?


my $e = {
};
for my $c (sort keys %$cat) {
        push @{$e->{categories}},
            {
                name => $c,
                url => "$c"
            };
}
$template->process('main.tt2', $e, "index.html") or die;

<ul>
[% FOREACH c IN categories -%]
<li><a href="[% c.url | url %]">[% c.name %]</a></li>
[% END %]
</ul>
Was it helpful?

Solution

$e->{somethingElse} = "some value";

and

[% somethingElse | html %]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top