[stringtemplate-interest] alternating row colows

Nate misc at n4te.com
Thu Mar 1 17:54:12 PST 2007


This would be acceptable if I could create a template reference inline. 
However, AFAIK I would have to either put my row template in its own 
file or in a group file. This would fragment my templates, making them 
much harder to follow.

-Nate


Terence Parr wrote:
> how about using a template reference instead of an anonymous template  
> and then pass a different color:
>
> $stuff:row(color="red"), row(color="green")$
>
> I *think* that works. ;)
>
> Ter
> On Mar 1, 2007, at 4:30 PM, Nate wrote:
>
>   
>> I know ST supports alternating templates, eg...
>>
>> $stuff:redRow(),greenRow()$
>>
>> However, I don't see this as being useful for rendering an HTML table
>> with alternating row colors. Am I expected to do the following?
>>
>> $stuff:{
>>     <tr class="red">
>>        <td>$it.firstName$</td>
>>        <td>$it.lastName$</td>
>>        <td>$it.address$</td>
>>     </tr>
>> },{
>>     <tr class="green">
>>        <td>$it.firstName$</td>
>>        <td>$it.lastName$</td>
>>        <td>$it.address$</td>
>>     </tr>
>> }$
>>
>> I don't want to duplicate my template just to change the row color. I
>> don't want to put my template in another file so it can be reused. I
>> just want to know if the current row is even or odd. This is purely
>> presentation logic, so it should be easy. Is there an easier way to
>> accomplish this in ST?
>>
>> In Smarty it is done with something like this...
>>
>> <tr class="{cycle values="green,red"}">
>>    <td>$it.firstName$</td>
>>    <td>$it.lastName$</td>
>>    <td>$it.address$</td>
>> </tr>
>>
>> -Nate


More information about the stringtemplate-interest mailing list