Reputation: 81
I couldn't find the answer to this one on the web.
Using Dancer and Template toolkit, I have an array of hashes which I would like to print to a table on my webapp. This is how I send the data structure to the template:
template "find_ip_results2", {
user => \@user,
};
What is the correct foreach syntax to iterate this structure and access each key-value pair?
Upvotes: 1
Views: 4846
Reputation: 1569
Slight modification to eugene y's answer to fix iterator syntax:
<ul>
[% FOREACH u IN user %]
<li>
communities: [% u.communities %]<br/>
priority: [% u.priority %]<br/>
policyName: [% u.policyName %]
</li>
[% END %]
</ul>
Upvotes: 1
Reputation: 149736
[% FOR u = user %]
[% u.key # or u.item('key') %]
[% END %]
You can read the docs here.
Upvotes: 4