forloop
父级 for loop 的信息。
| Properties | Type | Description |
|---|---|---|
first | boolean | 若当前迭代为第一次,则返回 true;否则返回 false。 |
last | boolean | 若当前迭代为最后一次,则返回 true;否则返回 false。 |
index | number | 当前迭代的从 1 开始的索引。 |
index0 | number | 当前迭代的从 0 开始的索引。 |
length | number | 循环中的迭代总次数。 |
rindex | number | 当前迭代的从 1 开始的逆序索引。 |
rindex0 | number | 当前迭代的从 0 开始的逆序索引。 |
{
"first":true,
"last":false,
"index":1,
"index0":0,
"rindex":4,
"rindex0":3,
"length":4
}
使用 forloop object
{% for i in (1..5) %}
{% if forloop.length > 0 %}
{{ i }}{% unless forloop.last %},{% endunless %}
{% endif %}
{% endfor %}
1, 2, 3, 4, 5