batch
¶
这个 batch
通过返回具有给定项数的列表来过滤“批处理”项。可以提供第二个参数,用于填充缺少的项:
1 2 3 4 5 6 7 8 9 10 11 | {% set items = ['a', 'b', 'c', 'd'] %}
<table>
{% for row in items|batch(3, 'No item') %}
<tr>
{% for column in row %}
<td>{{ column }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
|
上述示例将呈现为:
1 2 3 4 5 6 7 8 9 10 11 12 | <table>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>No item</td>
<td>No item</td>
</tr>
</table>
|
争论¶
size
:批次的大小;小数将四舍五入fill
:用于填写缺少的项目preserve_keys
:是否保留密钥