[% FOREACH item IN report.rows.values %] <tr> <td>[% item.id %]</td> <td>[% item.delta %] %</td> </tr> [% END %]
The values of the report.rows hash are not themselves hashes, but arrays. Therefore item.id makes no sense. item.0.id is more likely to be what you are after.
If you want to iterate over all items in the arrays you'll need a nested loop or some other means of iterating inside them. eg.
#!/usr/bin/env perl use strict; use warnings; use Template; my $r = { 'rows' => { 'category1' => [ {'id' => 'AAA', 'delta' => '0.01%'}, {'id' => 'BBB', 'delta' => '0.03%'} ], 'category2' => [ {'id' => 'CCC', 'delta' => '0.02%'}, {'id' => 'DDD', 'delta' => '0.04%'} ], }, }; my $text = q# [% FOREACH item IN report.rows.values %] [% FOREACH one IN item %] <tr> <td>[% one.id %]</td> <td>[% one.delta %] %</td> </tr> [% END %] [% END %] #; my $tt = Template->new; $tt->process (\$text, {report => $r});
In reply to Re: Perl Template + html: hash keys and values keyword not working
by hippo
in thread Perl Template + html: hash keys and values keyword not working
by feiiiiiiiiiii
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |