What's a good, simple way to have alternate row coloring with freemarker?
Is this really the best way?
<#assign row=0>
<#list items as item>
<#if (row % 2) == 0>
<#assign bgcolor="green">
<#else>
<#assign bgcolor="red">
</#if>
<tr style='background-color: ${bgcolor}'><td>${item}</td></tr>
<#assign row = row + 1>
</#list>
I tried doing this:
<#assign row=0>
<#list items as item>
<tr style='background-color: ${(row % 2) == 0 ? "green" : "blue"}'><td>${item}</td></tr>
<#assign row = row + 1>
</#list>
But apparently you can't user the ternary operator in there.
Note: I guess I should have mentioned it earlier, but I can't use css classes or javascript, since this HTML is going into an email message.
class='${["odd", "even"][item_index%2]}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With