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}は、値セットで交代するために使用されます.1つのテーブルに2つ以上の色を交互に出力し、値配列をループする場合に便利です.
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-5. {cycle}
    {/section}
    {section name=rows loop=$data}
    {$data[rows]}
    The above template would output:
    1 2 3
    [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