Edgewall Software

Changes between Initial Version and Version 1 of GenshiRecipes/AlternatingTableRows


Ignore:
Timestamp:
Jul 11, 2007, 6:47:14 AM (17 years ago)
Author:
eccentric@…
Comment:

created page

Legend:

Unmodified
Added
Removed
Modified
  • GenshiRecipes/AlternatingTableRows

    v1 v1  
     1= [GenshiRecipes Genshi Recipes]: Alternating Table Row Styles =
     2
     3When working with a list of data you wish to display in a table it is nice to have alternating table row styles for every other row (odd/even) to help make the data more readable. This can be done by using the ''enumerate'' function of python, and then using the index value from the function to decide if the row is odd or even by getting the remainder after dividing by 2. If the remainder is 1, the row is odd, otherwise the remainder is zero and the row is even.
     4
     5Using py:for to loop through the list you can do the following:
     6{{{
     7#!genshi
     8<tr py:for="i, (firstname, lastname) in enumerate(nameslist)" class="${i%2 and 'odd' or 'even'}">
     9}}}
     10
     11This will produce a table row in the html output with the ''class="odd"'' or ''class="even"'' alternating on each row.