🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# `batch` New in version 1.12.3: The `batch` filter was added in Twig 1.12.3. The `batch` filter "batches" items by returning a list of lists with thegiven number of items. A second parameter can be provided and used to fill inmissing items: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 2 3 4 5 6 7 8 9 10 11</pre></div></td><td class="code"><div class="highlight"><pre>{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %} &lt;table&gt; {% for row in items|batch(3, 'No item') %} &lt;tr&gt; {% for column in row %} &lt;td&gt;{{ column }}&lt;/td&gt; {% endfor %} &lt;/tr&gt; {% endfor %} &lt;/table&gt; </pre></div></td></tr></table> The above example will be rendered as: <table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17</pre></div></td><td class="code"><div class="highlight"><pre>&lt;table&gt; &lt;tr&gt; &lt;td&gt;a&lt;/td&gt; &lt;td&gt;b&lt;/td&gt; &lt;td&gt;c&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;d&lt;/td&gt; &lt;td&gt;e&lt;/td&gt; &lt;td&gt;f&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;g&lt;/td&gt; &lt;td&gt;No item&lt;/td&gt; &lt;td&gt;No item&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </pre></div></td></tr></table> ### Arguments - `size`: The size of the batch; fractional numbers will be rounded up - `fill`: Used to fill in missing items