Get Smarty


Donate Bitcoin Bitcoin

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Buy cheap glasses from and save up to 80%.

Where to buy prescription glasses? is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping -

Find Wedding Dresses Online at Canada from

Discount Wedding Dresses at

soccer kp is New 2016 Nike Mercurial Superfly V soccer cleats from



{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 Name Type Required Default Description
name string No default The name of the cycle
values mixed Yes N/A The values to cycle through, either a comma delimited list (see delimiter attribute), or an array of values
print boolean No TRUE Whether to print the value or not
advance boolean No TRUE Whether or not to advance to the next value
delimiter string No , The delimiter to use in the values attribute
assign string No n/a The template variable the output will be assigned to
reset boolean No FALSE The cycle will be set to the first value and not advanced
  • You can {cycle} through more than one set of values in a template by supplying a name attribute. Give each {cycle} an unique name.

  • You can force the current value not to print with the print attribute set to FALSE. This would be useful for silently skipping a value.

  • The advance attribute is used to repeat a value. When set to FALSE, the next call to {cycle} will print the same value.

  • If you supply the assign attribute, the output of the {cycle} function will be assigned to a template variable instead of being output to the template.

Example 8.2. {cycle}

{section name=rows loop=$data}
<tr class="{cycle values="odd,even"}">


The above template would output:

<tr class="odd">
<tr class="even">
<tr class="odd">


by anonymous on Nov 10, 2011 at 5:12
example of a common 2D loop pitfall:
{foreach from=$products item=product}
	{foreach from=$product.stats item=stat}
		<div class="{cycle values="odd,even"}">
the first product will always start with "odd", but if a product ends with "odd", the next product will start with "even".
p1 odd
p1 even
p1 odd
p2 even <-- probably not what we expect
solution: use the cycle name attribute, and give each cycle a unique name for each product:
{foreach from=$products item=product}
	{foreach from=$product.stats item=stat}
		<div class="{cycle values="odd,even" name=$}">
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Email: (not shown)
What is 9 plus 2? (Are you human?)