mawaru
mawaru

Reputation: 25

JsViews - Alternating Templates

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!

Upvotes: 1

Views: 485

Answers (1)

pedz
pedz

Reputation: 2349

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.

Upvotes: 3

Related Questions