开发者

Nesting included Twig templates?

开发者 https://www.devze.com 2023-04-11 19:05 出处:网络
I\'d like to pass the output of an included Twig template to another included Twig template as a parameter, like so:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号