[Templates] reiterating thru hashes of hashes: How? template side

Andy Wardley abw@andywardley.com
Tue, 19 Nov 2002 10:25:51 +0000


JustSome person wrote:
> [% FOREACH u=a_group %]
>     [% FOREACH y=u.keys %]
>          [% y %]
>     // I've tried y.key or y.value..too,,and no luck
>     [% END %]
> [% END %]

The general recipes are these:

   [% FOREACH kv = some_hash %]
     [% kv.key %]  =>  [% kv.value %]
   [% END %]

That'll give you unsorted hash order.  If you want sorted keys (in
this case, sorted numerically), you can do this:

   [% FOREACH key = some_hash.keys.nsort %] 
      [% key %]  =>  [% some_hash.$key %]
   [% END %]

In your example, your values are nested hashes, so you could do
something like this:

   [% FOREACH u = a_group %] 
      [% FOREACH y = u.value %]
         [% y.key %]  =>  [% y.value %]
      [% END %]
   [% END %]

HTH
A