如何使Twig全局变量在使用include标签后保持修改?我期望的输出是“set @ deeper”,但实际上得到的是“original setting”。
app/config/config.yml
twig:
globals:
testvar: "original setting"
root.html.twig
{% include "MyBundle::levelone.html.twig" %}
{{ testvar }}
levelone.html.twig
{% set testvar = "set @ levelone" %}
{% include "MyBundle::deeper.html.twig" %}
deeper.html.twig
{% set testvar = "set @ deeper" %}
{% set testvar %}
和{{ testvar }}
包裹在{%block global_test %}
中。 - Florian Klein