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>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nbsp; }]<br>%&gt;<br><br>I try with :<br>&lt=
;% foreach c in comments({id_table =3D&gt; 'Blog'}) %&gt;&lt;% c.id %&gt;&l=
t;% end %&gt; <br><br>Result : <br>123<br><br>I want only : 1 &amp; 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 " &lt;gertli=
[email protected]&gt;<br>A : "thorshand" &lt;[email protected]&gt;<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>&gt; On 04 Feb 2015, at 12:13, thors=
hand <[email protected]> wrote:<br>&gt; <br>&gt; Hi,<br>&gt; <br>&gt; Is it =
possible to iterate over a key value, like : <br>&gt; <br>&gt; &lt;% foreac=
h c in comment({id_table =3D 'Blog'}) %&gt;<br>&gt;    &lt;% c.date %&gt; &=
lt;% c.id %&gt;<br>&gt; &lt;% end %&gt;<br>&gt; <br>&gt; comment is a resul=
set of dbix search with columns : id, id_table, name, date, ... <br>&gt; I =
would like to make one dbi request (don't include where clause in resultset=
) to do this after :<br>&gt; <br>&gt; &lt;% foreach table in ('Blog', 'Wiki=
' ...) %&gt;<br>&gt;    &lt;% foreach c in comment({id_table =3D table}) %&=
gt;<br>&gt;       &lt;% c.date %&gt; &lt;% c.id %&gt;<br>&gt;    &lt;% end =
%&gt;<br>&gt; &lt;% end %&gt;<br>&gt; <br>&gt; Thanks<br>&gt; _____________=
__________________________________<br>&gt; templates mailing list<br>&gt; t=
[email protected]<br>&gt; 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==--