ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# `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