2016-01-13 48 views
0

在我的主頁上,我想使用我定義爲其他頁面的部分。在我的導航之後,我有一部分在我的網站上作爲獨立頁面運行的新聞和團隊成員。它看起來是這樣的:簡化化合物擴展

Header 
Nav 
<div class="content"> 
    {% include 'news.html' %} 
    {% include 'officers.html' %} 
</div> 
Footer 

所以我的新聞有一些基本的HTML,但爲了不克隆我的頭和NAV我要加入這一行:

{% if page_data.current_page == 'news' %} {% extends "base.html" %} {% endif %} 

是否有辦法爲了簡化這個陳述?

回答

0

來處理這一問題的替代辦法是的news.html身體移動到局部,例如partials/news.html,然後include它在這兩個您的主頁,並在新聞頁面本身:

{# home.html #} 
Header 
Nav 
<div class="content"> 
    {% include 'partials/news.html' %} 
    {% include 'officers.html' %} 
</div> 
Footer 

然後在news.html

{% extends "base.html" %} 
{% block where_news_belongs %} 
    {{ super() }} {# if we need to include the contents of the block #} 
    {% include 'partials/news.html %} 
{% endblock where_news_belongs %}