{% block someBlock %}
{% set foo = 'blah blah blah' %}
{% endblock %}
{% block otherBlock %}
{{ foo }}
{% endblock %}
这不能按预期工作(foo在第二个块中不可见)。如何使其全局可见并使其按预期工作?
答案 0 :(得分:1)
答案 1 :(得分:0)
foo
。
{# begin template "foo.html" #}
{% set foo = 'default value' %} {# defined bar.foo #}
{% block someBlock %}
{% set foo = 'blah blah blah' %} {# changes bar.foo #}
{{ foo }} {# outputs bar.foo #}
{% set baz = 'other' %} {# defined #}
{% endblock %}
{% block otherBlock %}
{{ foo }} {# outputs bar.foo #}
{{ baz }} {# undefined #}
{% endblock %}
{# template "main.html" #}
{% include "foo.html" as bar %}
{{ block('someBlock') }}
{{ block('otherBlock')}}