<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>{cycle}</title> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Smarty Manual"> <link rel="up" href="language.custom.functions.html" title="Chapter 8. Custom Functions"> <link rel="prev" href="language.function.counter.html" title="{counter}"> <link rel="next" href="language.function.debug.html" title="{debug}"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">{cycle}</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="language.function.counter.html">Prev</a> </td> <th width="60%" align="center">Chapter 8. Custom Functions</th> <td width="20%" align="right"> <a accesskey="n" href="language.function.debug.html">Next</a> </td> </tr> </table> <hr> </div> <div class="sect1" title="{cycle}"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="language.function.cycle"></a>{cycle}</h2></div></div></div> <p> <code class="varname">{cycle}</code> 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. </p> <div class="informaltable"><table border="1"> <colgroup> <col align="center"> <col align="center"> <col align="center"> <col align="center"> <col> </colgroup> <thead><tr> <th align="center">Attribute Name</th> <th align="center">Type</th> <th align="center">Required</th> <th align="center">Default</th> <th>Description</th> </tr></thead> <tbody> <tr> <td align="center">name</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>default</em></span></td> <td>The name of the cycle</td> </tr> <tr> <td align="center">values</td> <td align="center">mixed</td> <td align="center">Yes</td> <td align="center"><span class="emphasis"><em>N/A</em></span></td> <td>The values to cycle through, either a comma delimited list (see delimiter attribute), or an array of values</td> </tr> <tr> <td align="center">print</td> <td align="center">boolean</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td> <td>Whether to print the value or not</td> </tr> <tr> <td align="center">advance</td> <td align="center">boolean</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em><code class="constant">TRUE</code></em></span></td> <td>Whether or not to advance to the next value</td> </tr> <tr> <td align="center">delimiter</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>,</em></span></td> <td>The delimiter to use in the values attribute</td> </tr> <tr> <td align="center">assign</td> <td align="center">string</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em>n/a</em></span></td> <td>The template variable the output will be assigned to</td> </tr> <tr> <td align="center">reset</td> <td align="center">boolean</td> <td align="center">No</td> <td align="center"><span class="emphasis"><em><code class="constant">FALSE</code></em></span></td> <td>The cycle will be set to the first value and not advanced</td> </tr> </tbody> </table></div> <div class="itemizedlist"><ul class="itemizedlist" type="disc"> <li class="listitem"><p> You can <code class="varname">{cycle}</code> through more than one set of values in a template by supplying a <em class="parameter"><code>name</code></em> attribute. Give each <code class="varname">{cycle}</code> an unique <em class="parameter"><code>name</code></em>. </p></li> <li class="listitem"><p> You can force the current value not to print with the <em class="parameter"><code>print</code></em> attribute set to <code class="constant">FALSE</code>. This would be useful for silently skipping a value. </p></li> <li class="listitem"><p> The <em class="parameter"><code>advance</code></em> attribute is used to repeat a value. When set to <code class="constant">FALSE</code>, the next call to <code class="varname">{cycle}</code> will print the same value. </p></li> <li class="listitem"><p> If you supply the <em class="parameter"><code>assign</code></em> attribute, the output of the <code class="varname">{cycle}</code> function will be assigned to a template variable instead of being output to the template. </p></li> </ul></div> <div class="example"> <a name="id3065639"></a><p class="title"><b>Example 8.5. {cycle}</b></p> <div class="example-contents"> <pre class="programlisting"> {section name=rows loop=$data} <tr class="{cycle values="odd,even"}"> <td>{$data[rows]}</td> </tr> {/section} </pre> <p>The above template would output:</p> <pre class="screen"> <tr class="odd"> <td>1</td> </tr> <tr class="even"> <td>2</td> </tr> <tr class="odd"> <td>3</td> </tr> </pre> </div> </div> <br class="example-break"> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="language.function.counter.html">Prev</a> </td> <td width="20%" align="center"><a accesskey="u" href="language.custom.functions.html">Up</a></td> <td width="40%" align="right"> <a accesskey="n" href="language.function.debug.html">Next</a> </td> </tr> <tr> <td width="40%" align="left" valign="top">{counter} </td> <td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td> <td width="40%" align="right" valign="top"> {debug}</td> </tr> </table> </div> </body> </html>