我想爲使用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