I'd like to pass the output of an included Twig template to another included Twig template as a parameter, like so:
{% include 'MyBundle:Default:tpl1.html.twig' with {'item': include 'MyBundle:Default:tpl2.html.twig'} %}
Unfortunately, this does not work as the syntax is invalid. Any ideas how to nest templates like this / store the output of an included template in a variable? Or is there an alternative way to accomplish what I want to do? I thought about defining blocks in the included template, but it does not seem to be possible to overwrite them from the "outer" template ...
Twig is a modern template engine for PHPSecure: Twig has a sandbox mode to evaluate untrusted template code. This allows Twig to be used as a template language for applications where users may modify the template design.
In a Twig template, you can use the dump utility as a function or a tag: {% dump foo. bar %} is the way to go when the original template output shall not be modified: variables are not dumped inline, but in the web debug toolbar; on the contrary, {{ dump(foo.
Overriding templatesLocate the template you want to override. Copy the template file from its core location into your theme folder. Rename the template according to the naming conventions in order to target a more specific subset of areas where the template is used. Modify the template according to your wish.
Try settings the template's content in a variable:
{% set content %}
{% include 'foo' %}
{% endset %}
{% include 'bar' with {'item': content } %}
It should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With