我想为使用Twig的做一个引导主题。现在我正在菜单上工作。我一直在寻找如何使页面活跃,我一直在看到有关块的东西。现在我的index.html看起来像这样Twig中的include和block有什么区别?
{% include 'header.html' %}
<body>
{% include 'nav.html' %}
<div class="container"}
{{ content }}
{% include 'footer.html' %}
我nav.html看起来是这样的:
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation"><a class="{% if app.request.attributes.get('_route') starts with 'home' %}active{% endif %}">Home</a></li>
<li role="presentation"><a class="{% if app.request.attributes.get('_route') starts with 'about' %}active{% endif %}">About</a></li>
<li role="presentation"><a class="{% if app.request.attributes.get('_route') starts with 'contact' %}active{% endif %}">Contact</a></li>
</ul>
</nav>
<h3 class="text-muted">{{ site_title }}</h3>
</div>
这是正确的编码习惯,或者我应该做与块的东西吗?我真的不明白块如何工作。
感谢您的回答。大部分是有道理的。在块中使用导入是否是一种好的形式? – jonbon
此外,什么时候使用.twig vs .html? – jonbon
让我先回答第二个问题:这只是扩展,所以总是 - 如果你想使用树枝及其功能,你必须使用* .twig扩展名,并且是可以在块内部导入东西。例如,您可以创建一个用于在网站上显示错误的模板,并将其导入到任何要显示它们的位置。 – Robert