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 " <gertl...@me.com>
A : "thorshand" <thorsh...@sfr.fr>
Copie à : templates@template-toolkit.org
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
> templates@template-toolkit.org
> http://mail.template-toolkit.org/mailman/listinfo/templates



_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to