Output Modifiers

Create Odd-Even Classes

light fare

Using the Modulus Modifier

Most listing snippets provide an item index placeholder. Here's a neat trick for using the modulus Output Modifier to leverage that placeholder to generate even/odd classes.

The Solution:

lukemcd says...

I did not see this anywhere else on the forums so I thought I would share. Many extras such as Quip that generate a list of items use templates for those items. The templates often are given an ID ("idx" is the common placeholder). Sometimes you need to apply an odd/even class to those items. If you want to do it within the template you can use modulus output filter:

<li class="[[+idx:mod:isequalto=`1`:then=`even`:else=`odd`]]">[[+body]]</li>

What's the Story?

There are a number of built-in Output Modifiers to do mathematical transformations of output. The modulus modifier ('mod' or 'modulus') performs a modulus calculation on the output. By default it does %2, returning a 1 or a 0, so it's perfect to use to create classes based on an index placeholder.