List of Dictionaries with Genshi

12 views
Skip to first unread message

Enrico Heller

unread,
Oct 21, 2013, 8:01:39 AM10/21/13
to gen...@googlegroups.com
Hello there,

I'm new to genshi and want to output my own trac plugin with genshi. I have a list of dicionaries and i want to output this
by key

[0]
+ {id} 01
+ {name} hans
[1]
+ {id} 02
+ {name} claudia

and so on...

now i want to output these like this way.

 18                 <table>
 19                 <th>ID</th><th>Name</th>
 20                 <py:for each="row in results">
 21                         <tr>
 22                              <td>$row['id']</td>
 23                              <td>$row['name']</td>
 24                         </tr>
 25                 </py:for>
 26                 </table>

the syntax in line 22 and 23 is wrong but i can't find some exambles.
How I do it right

Thanks for your Help
Enrico

Felix Schwarz

unread,
Oct 21, 2013, 8:08:01 AM10/21/13
to gen...@googlegroups.com

Am 21.10.2013 14:01, schrieb Enrico Heller:
> 22 <td>$row['id']</td>
> 23 <td>$row['name']</td>

try ${row['id']} or the Genshi shortcut ${row.id}

fs

Simon Cross

unread,
Oct 21, 2013, 8:11:35 AM10/21/13
to gen...@googlegroups.com
Hi Enrico

See http://genshi.edgewall.org/wiki/Documentation/templates.html#synopsis.
You need to use something like:

<td>${row['id']}</td>

or

<td>${row.id}</td>

Schiavo
Simon

Enrico Heller

unread,
Oct 22, 2013, 2:38:09 AM10/22/13
to gen...@googlegroups.com
Hi there,

thanks for answers, i tryed a lil and found two solution that works for me. :)

 28                 <table>
 29                         <th>ID</th><th>Name</th><th>Vorname</th>
 30                                 <tr py:for="i in range(0, len(results2))">
 31                                         <td>${results2[i].id}</td>
 32                                         <td>${results2[i].vorname}</td>
 33                                         <td>${results2[i].name}</td>
 34                                 </tr>
 35                 </table>


 36                 <table>
 37                         <th>ID</th><th>Name</th><th>Vorname</th>
 38                                 <py:for each="row in results2">
 39                                         <tr>
 40                                         <td>${row.id}</td>
 41                                         <td>${row.vorname}</td>
 42                                         <td>${row.name}</td>
 43                                         </tr>
 44                                 </py:for>
 45                 </table>

Greetings
Enrico
Reply all
Reply to author
Forward
0 new messages