{cycle}

{cycle} is used to alternate a set of values. This makes it easy to for example, alternate between two or more colors in a table, or cycle through an array of values.

Attribute NameTypeRequiredDefaultDescription
namestringNodefaultThe name of the cycle
valuesmixedYesN/AThe values to cycle through, either a comma delimited list (see delimiter attribute), or an array of values
printbooleanNoTRUEWhether to print the value or not
advancebooleanNoTRUEWhether or not to advance to the next value
delimiterstringNo,The delimiter to use in the values attribute
assignstringNon/aThe template variable the output will be assigned to
resetbooleanNoFALSEThe cycle will be set to the first value and not advanced

Example 8-5. {cycle}

{section name=rows loop=$data}
<tr bgcolor="{cycle values="#eeeeee,#d0d0d0"}">
   <td>{$data[rows]}</td>
</tr>
{/section}

The above template would output:

<tr bgcolor="#eeeeee">
   <td>1</td>
</tr>
<tr bgcolor="#d0d0d0">
   <td>2</td>
</tr>
<tr bgcolor="#eeeeee">
   <td>3</td>
</tr>