save content of include in variable
twig
Solution
You can assign a chunk of text by using the following snippet:
main.twig
{% set foo %}
{% include 'foo.twig' %}
{% endset %}
{% set items = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] %}
<table>
{% for row in items|batch(3, foo) %}
<tr>
{% for column in row %}
<td>{{ column }}</td>
{% endfor %}
</tr>
{% endfor %}
</table>
foo.twig
<div>
<h1>Foo</h1>
</div>
twigfiddle
Problem
I have a twig template that uses `batch()` to make some columns like that: ``` {% set rows = collection|batch(3) %} ``` As documented here: http://twig.sensiolabs.org/doc/filters/batch.html this function takes a second argument to define the string that is used for "missing" elements. I am looking for something like that: ``` {% set html = include 'path/to/file.html.twig' %} <-- parse error {% set rows = collection|batch(3, html) %} ``` Is there a way to do that or something else I can/should do?