Re: Iterate over keys value
thorshand <[email protected]> Thu, 5 Feb 2015 10:12:23 +0100 (CET)
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <400135965.712144.1423127543161.JavaMail.www@wsfrf1320> |
--===============4578000037230581236==
Content-Type: multipart/alternative;
boundary="----=_Part_712143_1816830494.1423127543160"
------=_Part_712143_1816830494.1423127543160
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Doesn't work.
dbix seems return array of hash like this :
<% comments =3D [
=C2=A0=C2=A0=C2=A0 {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 id'=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D> 1,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'id_table'=C2=A0=C2=A0=C2=A0 =3D=
> 'Blog',
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'comment'=C2=A0=C2=A0=C2=A0=C2=
=A0 =3D> 'Hello'
=C2=A0=C2=A0=C2=A0 },
=C2=A0=C2=A0=C2=A0 {=C2=A0=20
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'id'=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D> 2,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'id_table'=C2=A0=C2=A0=C2=A0 =3D=
> 'Blog',
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'comment'=C2=A0=C2=A0=C2=A0=C2=
=A0 =3D> 'Hello world'
=C2=A0=C2=A0=C2=A0 },
=C2=A0=C2=A0=C2=A0 {=C2=A0=20
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'id'=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D> 3,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'id_table'=C2=A0=C2=A0=C2=A0 =3D=
> 'Wiki',
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 'comment'=C2=A0=C2=A0=C2=A0=C2=
=A0 =3D> 'Test'
=C2=A0=C2=A0=C2=A0 }]
%>
I try with :
<% foreach c in comments({id_table =3D> 'Blog'}) %><% c.id %><% end %>=20
Result :=20
123
I want only : 1 & 2 here
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Message du : 04/02/2015 19:41
De : "Gert van Oss " <[email protected]>
A : "thorshand" <[email protected]>
Copie =C3=A0 : [email protected]
Sujet : Re: [Templates] Iterate over keys value
Maybe something like this gets you there..?
[% FOREACH country IN all_content.keys.sort %]
[% country %]
[% FOREACH line IN all_content.$country %]
=09 [% line.name %]
=09 [% line.street %]
=09 [% line.city %]
[% END %]
[% END %]
> On 04 Feb 2015, at 12:13, thorshand wrote:
>=20
> Hi,
>=20
> Is it possible to iterate over a key value, like :=20
>=20
> <% foreach c in comment({id_table =3D 'Blog'}) %>
> <% c.date %> <% c.id %>
> <% end %>
>=20
> comment is a resulset of dbix search with columns : id, id_table, name, d=
ate, ...=20
> I would like to make one dbi request (don't include where clause in resul=
tset) to do this after :
>=20
> <% foreach table in ('Blog', 'Wiki' ...) %>
> <% foreach c in comment({id_table =3D table}) %>
> <% c.date %> <% c.id %>
> <% end %>
> <% end %>
>=20
> Thanks
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
------=_Part_712143_1816830494.1423127543160
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Doesn't work.<br>dbix seems return array of hash like this :<br><br><% c=
omments =3D [<br> {<br> &nbs=
p; id' =3D> =
1,<br> 'id_table' &nbs=
p; =3D> 'Blog',<br> 'comment'&=
nbsp; =3D> 'Hello'<br> },<br> &=
nbsp; { <br> 'id'&nbs=
p; =3D> 2,<br> &nbs=
p; 'id_table' =3D> 'Blog=
',<br> 'comment'  =
; =3D> 'Hello world'<br> },<br>  =
; { <br> 'id' &n=
bsp; =3D> 3,<br> &n=
bsp; 'id_table' =3D> 'Wiki',<br>&nbs=
p; 'comment' =
=3D> 'Test'<br> }]<br>%><br><br>I try with :<br><=
;% foreach c in comments({id_table =3D> 'Blog'}) %><% c.id %>&l=
t;% end %> <br><br>Result : <br>123<br><br>I want only : 1 & 2 here<=
br><br><br><br><br><br><br><br>=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D<br><br>Message du : 04/02/2015 19:41<br>De : "Gert van Oss " <gertli=
[email protected]><br>A : "thorshand" <[email protected]><br>Copie =C3=A0 :=
[email protected]<br>Sujet : Re: [Templates] Iterate over key=
s value<br><br><br> Maybe something like this gets you there..?<br><br>[% F=
OREACH country IN all_content.keys.sort %]<br> <h3>[% country %]</h3><br=
> [% FOREACH line IN all_content.$country %]<br>=09 [% line.name %]=
<br><br>=09 [% line.street %]<br><br>=09 [% line.city %]<br><br> =
[% END %]<br> [% END %]<br><br><br>> On 04 Feb 2015, at 12:13, thors=
hand <[email protected]> wrote:<br>> <br>> Hi,<br>> <br>> Is it =
possible to iterate over a key value, like : <br>> <br>> <% foreac=
h c in comment({id_table =3D 'Blog'}) %><br>> <% c.date %> &=
lt;% c.id %><br>> <% end %><br>> <br>> comment is a resul=
set of dbix search with columns : id, id_table, name, date, ... <br>> I =
would like to make one dbi request (don't include where clause in resultset=
) to do this after :<br>> <br>> <% foreach table in ('Blog', 'Wiki=
' ...) %><br>> <% foreach c in comment({id_table =3D table}) %&=
gt;<br>> <% c.date %> <% c.id %><br>> <% end =
%><br>> <% end %><br>> <br>> Thanks<br>> _____________=
__________________________________<br>> templates mailing list<br>> t=
[email protected]<br>> http://mail.template-toolkit.org/mail=
man/listinfo/templates<br><br> </[email protected]>
------=_Part_712143_1816830494.1423127543160--
--===============4578000037230581236==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates
--===============4578000037230581236==--