Get Smarty

Donate

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

Buy cheap glasses from Cheapglasses123.com and save up to 80%.

Where to buy prescription glasses? EyewearCanada.com is your best choice!

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Shop for 2018 World Cup Football Boots Online sale at guthjcc.com

Browse best 2018 world cup soccer cleats and shoes from SoccerAzteca.com

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.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 20 plus 20? (Are you human?)

Advertisement