我使用 Twig 创建了三个模板。第一个A
定义了块,第二个从第一个扩展,但包括第三个模板,它设置块的内容A
。
通过浏览器加载呈现 b.html.twig 的 url 时,块中的内容A
(由第 3 个模板定义)未定义块 _A。
例子:
<!-- base.html.twig -->
{% block _css '' %}
{% block _header '' %}
{% block _content '' %}
{% block _footer '' %}
{% block _js '' %}
<!-- layout.html.twig -->
<!-- header and footer are placed in the raight zone -->
{% extends ::base.html.twig %}
{% block _header %}
{% render "MyBundleBundle:Header:header" %}
{% endblock %}
{% block _footer %}
{% render "MyBundleBundle:Footer:footer" %}
{% endblock %}
<!-- my_template.html.twig -->
<!-- content is also placed in the right zone but css and js blocks in the included template are not placed where declared in base.html.twig -->
{% extends MyBundleBundle::layout.html.twig %}
{% block _content %}
SOME_CONTENT
{% include MyBundleBundle::my_included_template.html.twig %}
{% endblock %}
<!-- my_included_template.html.twig -->
{% block _css %}
<link.......................>
{% endblock %}
{% block _js %}
<script..................>
{% endblock %}
MORE CONTENT BELONGING TO THE INCLUDED TEMPLATE
我在这里期望的是,_css 阻止内容出现在页面顶部,_js 阻止内容出现在底部,但这并没有发生。我希望你能看到我哪里出错了,谢谢!