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')-&gt;resultset('myTable')-&gt;search( { Date
    =&gt; $current },     { order_by =&gt; 'NumClient'} );<br>
    return template 'sauvegarde/index'  =&gt; {<br>
                                            rs          =&gt; $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>
                   &lt;td&gt;   [% result.id %]       &lt;/td&gt;<br>
                   &lt;td&gt;   [% result.id_table %]       &lt;/td&gt;<br>
                   &lt;td&gt;   [% result.comment%]       &lt;/td&gt;<br>
    ....<br>
    <br>
    [% END %]<br>
    <br>
    if you want to force simple json with dbix see this option <br>
    <br>
    { result_class =&gt; '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>
      &lt;% comments = [<br>
          {<br>
              id'          =&gt; 1,<br>
              'id_table'    =&gt; 'Blog',<br>
              'comment'     =&gt; 'Hello'<br>
          },<br>
          {  <br>
              'id'          =&gt; 2,<br>
              'id_table'    =&gt; 'Blog',<br>
              'comment'     =&gt; 'Hello world'<br>
          },<br>
          {  <br>
              'id'          =&gt; 3,<br>
              'id_table'    =&gt; 'Wiki',<br>
              'comment'     =&gt; 'Test'<br>
          }]<br>
      %&gt;<br>
      <br>
      I try with :<br>
      &lt;% foreach c in comments({id_table =&gt; 'Blog'}) %&gt;&lt;%
      c.id %&gt;&lt;% end %&gt; <br>
      <br>
      Result : <br>
      123<br>
      <br>
      I want only : 1 &amp; 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]">&lt;[email protected]&gt;</a><br>
      A : "thorshand" <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</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>
      &gt; On 04 Feb 2015, at 12:13, thorshand <[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;% foreach c in comment({id_table = 'Blog'}) %&gt;<br>
        &gt; &lt;% c.date %&gt; &lt;% c.id %&gt;<br>
        &gt; &lt;% end %&gt;<br>
        &gt; <br>
        &gt; comment is a resulset 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 = 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; <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a><br>
        &gt; <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==--