【发布时间】:2016-08-11 22:40:27
【问题描述】:
我正在使用 Twig 作为模板引擎,并且我有一个通用的右侧边栏,应包含在所有页面上。
_base.twig
/* Page HTML header */
{% block content %} {% endblock %}
/* Page HTML Footer */
index.twig
{% extends "_base.twig" %}
{% block content %}
<div id="left-bar">Dynamic Content</div>
<div id="right-bar">Static Content</div>
{% endblock %}
about.twig
{% block content %}
<div id="left-bar">Dynamic Content</div>
<div id="right-bar">Static Content</div>
{% endblock %}
.... 很多页面等等.. 我希望 right-bar 成为一个外部页面,并且应该包含在每个页面中,因为内容始终相同。
我尝试使用{% extends %} 两次,但 Twig 失败,因为我读到不允许多次扩展。所以请任何解决方案。
【问题讨论】:
-
你试过使用'use'标签吗? twig.sensiolabs.org/doc/tags/use.html