如何在速度模板中使用“for”循环?

2022-09-01 11:12:45

我刚刚在谷歌上搜索了“for loop”,但看起来速度只有“foreach”。

如何在速度模板中使用“for循环”?


答案 1

想要添加 foreach 循环中的迭代信息可以从特殊属性访问:$foreach

#foreach ($foo in $bar)
    count: $foreach.count
    index: $foreach.index
    first: $foreach.first 
    last:  $foreach.last
#end

(上次我检查时包含一个错误)last


答案 2

只有.你必须在你的上下文中加入一些可迭代的东西。例如,提供数组或某种类型:#foreachbarCollection

#foreach ($foo in $bar)
    $foo
#end

或者,如果要循环访问数字范围:

#foreach ($number in [1..34])
    $number
#end