Pass include path from variable with Twig? -
i need include child-1.twig , child-2.twig in component.twig, , include component.twig in page.twig.
in page.twig:
{% set items = [ '{% include "child-1.twig" %}', '{% include "child-2.twig" %}' ] %} {% include "component.twig" items %}
in component.twig:
<div class="component"> {% item in items %} {{ item }} {% endfor %} </div>
the complexity comes fact cant modify component.twig, page.twig. code above work if {% include "child-1.twig" %}
, {% include "child-2.twig" %}
rendered instead printed onto page string of text.
can similar approach make child include run?
can suggest add empty block in file (component.twig
)
{% block includes %}{% endblock %}
then able this:
{% embed "component.twig" items %} {% block includes %} {% include "child-1.twig" %} {% include "child-2.twig" %} {% endblock %} {% endembed %}
Comments
Post a Comment