2012-09-04 50 views
0

我期待與定製的DjangoCMS模板sub_menu.html,並已得到了目前在菜單下面的代碼:DjangoCMS/Django的 - 如果檢測到當前頁面是孩子

{% if children %} 
<div class="unit subnav"> 
<h3>{% page_attribute "menu_title" %}</h3> 
<ul> 
    {% for child in children %} 
     <li class="{% if child.selected %}on{% endif %}{% if child.ancestor %}ancestor{% endif %}{% if child.sibling %}sibling{% endif %}{% if child.descendant %}descendant{% endif %}"> 
      <a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}" title="{{ child.get_menu_title }}">{{ child.get_menu_title }}</a> 
     </li> 
    {% endfor %} 
    </ul> 
</div> 
{% endif %} 

所以基本上,這個檢測如果該頁面有子項,並且如果存在該頁面的子項,則添加子導航。

到目前爲止,這麼好。

我的問題是,當我導航到自己的子頁面 - 菜單消失,所以我想檢測頁面是否是1級以下的「孩子」。這應該停止所有具有導航的頁面(因爲他們都是我設想的首頁的子女),但應允許低於主要導航級別的人員出現菜單。

如果任何人都能伸出援助之手或指向正確的方向,那就太棒了。

回答

2

確定,它可能沒有什麼意義的人,但我可以去這條底線我subnav模板中的if語句下面...

{% if children or request.current_page.level > 0 %} subnav in here {% endif %} 
相關問題