Get Smarty

Donate

Paypal

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

Advertisement

{for}

{for}{forelse} タグは、シンプルなループを作ります。 次の形式に対応しています。

  • {for $var=$start to $end} 1 ずつ増えていくシンプルなループ。

  • {for $var=$start to $end step $step} 増分を指定するループ。

{forelse} は、ループの処理が行われなかった場合に実行されます。

属性

属性名 短縮形 必須 デフォルト 概要
max n/a integer No n/a 反復処理の制限数

オプションのフラグ

名前 概要
nocache {for} ループのキャッシュを無効にする

Example 7.27. シンプルな {for} ループ


<ul>
{for $foo=1 to 3}
    <li>{$foo}</li>
{/for}
</ul>

  

上の例の出力は次のようになります。


<ul>
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>

  

Example 7.28. max 属性の使用


$smarty->assign('to',10);

  

<ul>
{for $foo=3 to $to max=3}
    <li>{$foo}</li>
{/for}
</ul>

  

上の例の出力は次のようになります。


<ul>
    <li>3</li>
    <li>4</li>
    <li>5</li>
</ul>

  

Example 7.29. {forelse} の実行


$smarty->assign('start',10);
$smarty->assign('to',5);

  

<ul>
{for $foo=$start to $to}
    <li>{$foo}</li>
{forelse}
  no iteration
{/for}
</ul>

  

上の例の出力は次のようになります。


  no iteration

  

{foreach}{section} および {while} も参照ください。

Comments
No comments for this page.

Advertisement

Sponsors [info]

Sponsors