user1380641
user1380641

Reputation: 81

template toolkit - Iterating through array of hashes

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

Answers (2)

yahermann
yahermann

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

Eugene Yarmash
Eugene Yarmash

Reputation: 149736

[% FOR u = user %]
    [% u.key    # or u.item('key') %]
[% END %]

You can read the docs here.

Upvotes: 4

Related Questions