Learn

switch

Iterate over values.

{{ switch }}

For each time that this tag is called, a value from those listed in the between parameter will be returned. The first value will be returned the first time this tag is called, the second value the second time, etc. Once this tag runs out of values to return, it starts over at the first thing in its list.

Sample Usage

<table>
    <tbody>
        {{ entries:listing }}
            <tr class="{{ switch between="odd|even" }}">
                <th>{{ title }}</th>
                <td>{{ rating }}</td>
            <tr>
        {{ /entries:listing }}
    </body>
</table>

Parameters

This tag accepts the following parameters:

  • between — the set of values to iterate over, this should be a pipe-separated string

You can specify how many times each value should be repeated by using a colon syntax.
{{ switch between="left:3|right:2" }} would output left, left, left, right, right.

This article was last updated on September 13th, 2016. Find an error? Please let us know!