mirror of
https://github.com/twigphp/Twig.git
synced 2026-10-27 14:16:08 +00:00
c2a264a91d
* 1.x: Enhancement: Introduce DOCtor-RST config + Sphinx build + GithubActions Enhancement: Use GithubActions instead of Travis for tests Fix `odd` not working for negative numbers Bump version to 1.44.2-DEV Prepare the 1.44.1 release
45 lines
963 B
ReStructuredText
45 lines
963 B
ReStructuredText
``batch``
|
|
=========
|
|
|
|
The ``batch`` filter "batches" items by returning a list of lists with the
|
|
given number of items. A second parameter can be provided and used to fill in
|
|
missing items:
|
|
|
|
.. code-block:: html+twig
|
|
|
|
{% 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>
|
|
|
|
The above example will be rendered as:
|
|
|
|
.. code-block:: html+twig
|
|
|
|
<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>
|
|
|
|
Arguments
|
|
---------
|
|
|
|
* ``size``: The size of the batch; fractional numbers will be rounded up
|
|
* ``fill``: Used to fill in missing items
|
|
* ``preserve_keys``: Whether to preserve keys or not
|