1
votes

Does anyone know how would you apply an alternating template using JsViews?

For example is there a way to generate markup like this?

<table>
 <thead></thead>
 <tbody>
   <tr class="odd"></tr>
   <tr class="even"></tr>
 </tbody>    
</table>

Thanks!

1

1 Answers

3
votes

Within a template, the index is available using #index

There is an {{if}} construct that can be used to alternate between two choices.

The untested code would be something like:

{{if #index % 2 }}
    code for odd case
{{else}}
    code for even case
{{/if}}

Do a view source of this to see a simple use of #index.

Do a view source of this to see a simple use of if, then, else.