Freemarker: Html Table odd or even rows with Freemarker
April 9th, 2009 by jeremychoneWhen 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>
[#list docs as doc]
[#assign trCss = (doc_index % 2 == 0)?string("","odd")]
<tr class=”${trCss}”>
<td>some data</td>
</tr>
[/#list]
</table>
June 13th, 2010 at 3:26 pm
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!