Smarty - 手册 - 第8章 自定义函数 - {cycle}循环
{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.
{cycle} 用于在值集合中轮换。便于实现下述情况,在一个表格中交替输出两种或多种颜色,在值数组中循环。
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 |
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.
[cycle用途]
循环输出值[cycle文档]
http://smarty.php.net/manual/en/language.function.cycle.php
[Smarty下载地址]
http://smarty.php.net/download.php[Smarty相关论坛]
http://php.board.newsmth.net/[Smarty关键词]
smarty[Smarty函数]
借助cycle实现循环输出值, http://smarty.php.net/manual/en/language.function.cycle.php
Smarty的cat函数, http://smarty.php.net/manual/en/language.modifier.cat.php
Smarty的upper函数, http://smarty.php.net/manual/en/language.modifier.upper.php
{assign}标记, http://smarty.php.net/manual/en/language.custom.functions.php#language.function.assign
escape转义修饰符, http://smarty.php.net/manual/en/language.modifier.escape.php
counter计数器, http://smarty.php.net/manual/en/language.function.counter.php
[手册 - 第3章 基础语法]
Comments注释, http://smarty.php.net/manual/en/language.basic.syntax.php#language.syntax.commentsMath数学运算, http://smarty.php.net/manual/en/language.math.php