forloop
有关父级 for 循环的信息。
只有在 for 循环中存在。
属性
如果当前迭代是第一次,则返回 true。如果不是,则返回 false。
当前迭代的从 1 开始的索引。
当前迭代的从 0 开始的索引。
如果当前迭代是最后一次,则返回 true。如果不是,则返 回 false。
循环中的总迭代次数。
父 forloop 对象。如果当前 for 循环没有嵌套在另一个 for 循环中,则返回 null。使用 parentloop 属性。
当前迭代的从 1 开始的索引,按相反顺序排列。
当前迭代的从 0 开始的索引,按相反顺序排列。
例子
{{#var arr = "one,two,three" | split(",") /}}
{{#for item in arr}}
- {{ forloop.index }} {{ item }}
{{/for}}
嵌套循环
{{#var arr1 = "one,two,three" | split(",") /}}
{{#var arr2 = "four,five,six" | split(",") /}}
{{#for item1 in arr1}}
- parent: {{ forloop.index }} {{ item1 }}
{{#for item2 in arr2}}
- nested: {{ forloop.index }} {{ item2 }} parent: {{forloop.parentloop.index}}
{{/for}}
{{/for}}
这篇文章对你有帮助吗?
SHOPLINE