I'm having trouble accessing the hash value when I'm combining items to create the hash key. I'm hoping there's a better way to do this.

[% FOREACH num IN [ 1, 2, 3, 4, 5 ] %]
   [% box_key = ( 'box_' _ num ) %]
   [% name  = hash.$box_key.name %]
   [% phone = hash.$box_key.phone %]
[% END %] 
I think a nicer way to do this is to use "FOREACH auto-import" feature:
 
[% FOREACH hash.values.sort( 'name' ) %]
name is [% name %]
phone is [% phone %]
[% END %]
 
This will sort results by 'name' field.
 
Or do you need to preserve that "box_$i" order? No problem:
 
[% FOREACH hash.list.sort( 'key' ) %]
the "box" key is [% key %]
name is [% value.name %]
phone is [% value.phone %]
[% END %]
 

--
Sergey Martynoff

Reply via email to