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 ...
Try settings the template's content in a variable:
{% set content %}
{% include 'foo' %}
{% endset %}
{% include 'bar' with {'item': content } %}
It should work.
精彩评论