[Templates] hash key
Sergey Martynoff
sergey@martynoff.info
Wed, 15 Feb 2006 03:43:15 +0300
This is a multi-part message in MIME format.
------=_NextPart_000_0081_01C631E1.F7F355C0
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
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
------=_NextPart_000_0081_01C631E1.F7F355C0
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2900.2802" name=3DGENERATOR></HEAD>
<BODY>
<DIV dir=3Dltr align=3Dleft><FONT face=3DArial color=3D#0000ff=20
size=3D2></FONT> </DIV>
<BLOCKQUOTE=20
style=3D"PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px =
solid; MARGIN-RIGHT: 0px">
<DIV></DIV>
<DIV>I'm having trouble accessing the hash value when I'm combining =
items to=20
create the hash key. I'm hoping there's a better way to do this. =
<BR><BR>[%=20
FOREACH num IN [ 1, 2, 3, 4, 5 ] %]<BR> [% box_key =3D ( =
'box_' _=20
num ) %] <BR> [% name =3D hash.$box_key.name=20
%]<BR> [% phone =3D hash.$box_key.phone %]<BR>[% END =
%]<SPAN=20
class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff=20
size=3D2> </FONT></SPAN></DIV></BLOCKQUOTE>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>I=20
think a nicer way to do this is to use "FOREACH auto-import"=20
feature:</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>[%=20
FOREACH hash.values.sort( 'name' ) %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>name=20
is [% name %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>phone=20
is [% phone %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>[% END=20
%]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>This=20
will sort results by 'name' field.</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>Or do=20
you need to preserve that "box_$i" order? No =
problem:</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2></FONT></SPAN> </DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>[%=20
FOREACH hash.list.sort( 'key' ) %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>the=20
"box" key is [% key %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>name=20
is [% value.name %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>phone=20
is [% value.phone %]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2>[% END=20
%]</FONT></SPAN></DIV>
<DIV><SPAN class=3D766052600-15022006></SPAN> </DIV>
<DIV><SPAN class=3D766052600-15022006><FONT face=3DArial color=3D#0000ff =
size=3D2><!-- Converted from text/plain format -->
<P><FONT size=3D2>--<BR>Sergey=20
Martynoff<BR></FONT></P></FONT></SPAN></DIV></FONT></SPAN></DIV></BODY></=
HTML>
------=_NextPart_000_0081_01C631E1.F7F355C0--