{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