phptemplate-talphptal

Zebra Striping with PHPTAL?


I'm trying out PHPTAL and I want to render a table with zebra stripes. I'm looping through a simple php assoc array ($_SERVER).

Note that I don't want to use jQuery or anything like that, I'm trying to learn PHPTAL usage!

Currently I have it working like this (too verbose for my liking):

<tr tal:repeat="item server">
  <td tal:condition="repeat/item/odd" tal:content="repeat/item/key" class="odd">item key</td>
  <td tal:condition="repeat/item/even" tal:content="repeat/item/key" class="even">item key</td>
  <td tal:condition="repeat/item/odd" tal:content="item" class="odd">item value</td>
  <td tal:condition="repeat/item/even" tal:content="item" class="even">item value</td>
</tr>

Basically I want some kind of conditional assignment on the fly, but I'm unsure of the syntax.


Solution

  • You could create expression modifier by writing phptal_tales_evenodd() function (see phptal_tales() in manual):

    <td tal:attributes="class evenodd:repeat/item/odd">