Re: [SPAM] [MessageLimit][testmode] [SPAM] Re: Iterate over keys value
Hugues <hugues-/DdMVrhbcspWk0Htik3J/[email protected]> Thu, 05 Feb 2015 10:32:20 +0100
| Newsgroups | gmane.comp.lang.perl.modules.template-toolkit |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
--===============8208690673468470039==
Content-Type: multipart/alternative;
boundary="------------050704020305030407070502"
This is a multi-part message in MIME format.
--------------050704020305030407070502
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit
if this code can help you
With dbix/dancer/TT I use this kind of code
in perl
my $rs = schema('MyDB')->resultset('myTable')->search( { Date =>
$current }, { order_by => 'NumClient'} );
return template 'sauvegarde/index' => {
rs => $rs,
};
in TT
[% WHILE (result=rs.next) %]
....
[% IF result.id_table == 'Blog' || result.id_table ==
'Table' %]
<td> [% result.id %] </td>
<td> [% result.id_table %] </td>
<td> [% result.comment%] </td>
....
[% END %]
if you want to force simple json with dbix see this option
{ result_class => 'DBIx::Class::ResultClass::HashRefInflator'}
bye
Hugues
Le 05/02/2015 10:12, thorshand a écrit :
> Doesn't work.
> dbix seems return array of hash like this :
>
> <% comments = [
> {
> id' => 1,
> 'id_table' => 'Blog',
> 'comment' => 'Hello'
> },
> {
> 'id' => 2,
> 'id_table' => 'Blog',
> 'comment' => 'Hello world'
> },
> {
> 'id' => 3,
> 'id_table' => 'Wiki',
> 'comment' => 'Test'
> }]
> %>
>
> I try with :
> <% foreach c in comments({id_table => 'Blog'}) %><% c.id %><% end %>
>
> Result :
> 123
>
> I want only : 1 & 2 here
>
>
>
>
>
>
>
> ========================================
>
> Message du : 04/02/2015 19:41
> De : "Gert van Oss " <[email protected]>
> A : "thorshand" <[email protected]>
> Copie à : [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 %]
> [% line.name %]
>
> [% line.street %]
>
> [% line.city %]
>
> [% END %]
> [% END %]
>
>
> > On 04 Feb 2015, at 12:13, thorshand wrote:
> >
> > Hi,
> >
> > Is it possible to iterate over a key value, like :
> >
> > <% foreach c in comment({id_table = 'Blog'}) %>
> > <% c.date %> <% c.id %>
> > <% end %>
> >
> > comment is a resulset of dbix search with columns : id, id_table,
> name, date, ...
> > I would like to make one dbi request (don't include where clause in
> resultset) to do this after :
> >
> > <% foreach table in ('Blog', 'Wiki' ...) %>
> > <% foreach c in comment({id_table = table}) %>
> > <% c.date %> <% c.id %>
> > <% end %>
> > <% end %>
> >
> > Thanks
> > _______________________________________________
> > templates mailing list
> > [email protected]
> > http://mail.template-toolkit.org/mailman/listinfo/templates
>
>
>
> _______________________________________________
> templates mailing list
> [email protected]
> http://mail.template-toolkit.org/mailman/listinfo/templates
--------------050704020305030407070502
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit
<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
if this code can help you<br>
<br>
With dbix/dancer/TT I use this kind of code<br>
<br>
in perl<br>
my $rs = schema('MyDB')->resultset('myTable')->search( { Date
=> $current }, { order_by => 'NumClient'} );<br>
return template 'sauvegarde/index' => {<br>
rs => $rs,<br>
};<br>
<br>
<br>
in TT<br>
<br>
[% WHILE (result=rs.next) %]<br>
....<br>
[% IF result.id_table == 'Blog' || result.id_table ==
'Table' %] <br>
<td> [% result.id %] </td><br>
<td> [% result.id_table %] </td><br>
<td> [% result.comment%] </td><br>
....<br>
<br>
[% END %]<br>
<br>
if you want to force simple json with dbix see this option <br>
<br>
{ result_class => 'DBIx::Class::ResultClass::HashRefInflator'}<br>
<br>
<br>
<br>
bye<br>
Hugues<br>
<br>
<div class="moz-cite-prefix">Le 05/02/2015 10:12, thorshand a
écrit :<br>
</div>
<blockquote
cite="mid:400135965.712144.1423127543161.JavaMail.www@wsfrf1320"
type="cite">Doesn't work.<br>
dbix seems return array of hash like this :<br>
<br>
<% comments = [<br>
{<br>
id' => 1,<br>
'id_table' => 'Blog',<br>
'comment' => 'Hello'<br>
},<br>
{ <br>
'id' => 2,<br>
'id_table' => 'Blog',<br>
'comment' => 'Hello world'<br>
},<br>
{ <br>
'id' => 3,<br>
'id_table' => 'Wiki',<br>
'comment' => 'Test'<br>
}]<br>
%><br>
<br>
I try with :<br>
<% foreach c in comments({id_table => 'Blog'}) %><%
c.id %><% end %> <br>
<br>
Result : <br>
123<br>
<br>
I want only : 1 & 2 here<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
========================================<br>
<br>
Message du : 04/02/2015 19:41<br>
De : "Gert van Oss " <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]"><[email protected]></a><br>
A : "thorshand" <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]"><[email protected]></a><br>
Copie à : <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a><br>
Sujet : Re: [Templates] Iterate over keys value<br>
<br>
<br>
Maybe something like this gets you there..?<br>
<br>
[% FOREACH country IN all_content.keys.sort %]<br>
<h3>[% country %]</h3>
<br>
[% FOREACH line IN all_content.$country %]<br>
[% line.name %]<br>
<br>
[% line.street %]<br>
<br>
[% line.city %]<br>
<br>
[% END %]<br>
[% END %]<br>
<br>
<br>
> On 04 Feb 2015, at 12:13, thorshand <[email protected]>
wrote:<br>
> <br>
> Hi,<br>
> <br>
> Is it possible to iterate over a key value, like : <br>
> <br>
> <% foreach c in comment({id_table = 'Blog'}) %><br>
> <% c.date %> <% c.id %><br>
> <% end %><br>
> <br>
> comment is a resulset 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 = table}) %><br>
> <% c.date %> <% c.id %><br>
> <% end %><br>
> <% end %><br>
> <br>
> Thanks<br>
> _______________________________________________<br>
> templates mailing list<br>
> <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a><br>
> <a class="moz-txt-link-freetext" href="http://mail.template-toolkit.org/mailman/listinfo/templates">http://mail.template-toolkit.org/mailman/listinfo/templates</a><br>
<br>
</[email protected]>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
templates mailing list
<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>
<a class="moz-txt-link-freetext" href="http://mail.template-toolkit.org/mailman/listinfo/templates">http://mail.template-toolkit.org/mailman/listinfo/templates</a>
</pre>
</blockquote>
<br>
</body>
</html>
--------------050704020305030407070502--
--===============8208690673468470039==
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
--===============8208690673468470039==--