cycle

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

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

我們可以在一個數值的集合循環內使用 cycle,此函式可以讓我們很容易作到在表格內 使用兩個或多個顏色,或是在一個陣列內循環。

You can cycle through more than one set of values in your template by supplying a name attribute. Give each set of values a unique name.

樣版中,你只要指定 name 屬性就可以在 cycle 中使用多於一個集合的變數。請記得 給每個集合參數一個不同的名字。

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.

你可以設定 print 參數為 false,強迫不輸出現在的變數,通常用於要省略某個值時 。

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

使用 advance 屬性的話可以重複某個值。當你將 advance 的值設為 false 時,下一 個循環將會列印出相同的值。

If you supply the special "assign" attribute, the output of the cycle function will be assigned to this template variable instead of being output to the template.

如果你有使用 "assign" 屬性,則 cycle 函式的輸出會被指定給某個樣版變數而不會 直接輸出至樣版。

Example 8-3. cycle

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