Files
Twig/doc/filters/batch.rst
T
Fabien Potencier 4756b19b98 Merge branch '1.x'
* 1.x:
  fixed edge case where tests would fail because of a cache issue
  tweaked docs to avoid using an internal method in an example
  deprecated Twig_Environment::clearTemplateCache()
  fixed sandbox disabling when using the include function
  Example about how to rename several blocks
  fixed docs
  Update batch filter docs with arguments
2015-07-03 11:33:29 +02:00

49 lines
1013 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:: jinja
{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}
<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:: jinja
<table>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
</tr>
<tr>
<td>d</td>
<td>e</td>
<td>f</td>
</tr>
<tr>
<td>g</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