Smarty - 手册 - 第8章 自定义函数 - {cycle}循环

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 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
  • 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-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>

[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.comments
Math数学运算, http://smarty.php.net/manual/en/language.math.php

[手册 - 第7章 内建函数]

{foreach},{foreachelse}, http://smarty.php.net/manual/en/language.function.foreach.php

[手册 - 第13章 Smarty类方法]

register_function()动态注册模板函数插件, http://smarty.php.net/manual/en/api.register.function.php
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值