Freemarker: Html Table odd or even rows with Freemarker

April 9th, 2009 by jeremychone

When iterating on a list, you can use the “_index” value to css-mark the odd or even rows on a table.

<table>
[#list docs as doc]
[#assign trCss = (doc_index % 2 == 0)?string("","odd")]
<tr class=”${trCss}”>
<td>some data</td>
</tr>
[/#list]
</table>

One Response to “Freemarker: Html Table odd or even rows with Freemarker”

  1. Misha Nasledov Says:

    This is awesome, just what I’ve been looking for to improve some formatting in my application. I’m going to use this to intelligently fit two columns per row, too. Thanks!

Leave a Reply