2016-03-05 52 views
0

Django CMS自帶的標準menu.html看起來很簡單,但我無法弄清楚如何突出顯示當前有子級的菜單項。Django-CMS:如何讓當前活動的子頁面的父項目在導航菜單中突出顯示?

我嘗試這樣做:

{% if child.children and child.selected %} active dropdown{% endif %} 

但是,對於一些奇怪的原因,不能正常工作。

下面是menu.html的全碼:

{% load i18n menu_tags cache %} 

{% for child in children %} 
    <li class="{% if child.ancestor %}ancestor{% endif %} 
     {% if child.selected %} active{% endif %} 
     {% if child.children %} dropdown{% endif %} 
---> {% if child.selected and child.children %} active dropdown{% endif %}"> 
     {% if child.children %} 
      <a class="dropdown-toggle" data-toggle="dropdown" href="#"> 
       {{ child.get_menu_title }} <span class="caret"></span> 
      </a> 
      <ul class="dropdown-menu"> 
       {% show_menu from_level to_level extra_inactive extra_active template "" "" child %} 
      </ul> 
     {% else %} 
      <a href="{{ child.get_absolute_url }}"><span>{{ child.get_menu_title }}</span></a> 
     {% endif %} 
    </li> 
    {% if class and forloop.last and not forloop.parentloop %}{% endif %} 
{% endfor %} 

回答

0

由於Divio的馬丁Koistinen,我得到了一個有效的解決方案:

模板標籤和它的配置:

{% show_menu 0 1 0 0 "menu.html" %} 

Menu.html:

{% load i18n menu_tags cache %} 

{% for child in children %} 
<li class="{% if child.ancestor %}ancestor{% endif %}{% if child.selected %} active{% endif %}"> 
    <a href="{{ child.get_absolute_url }}">{{ child.get_menu_title }}</a> 
    </li> 
{% endfor %} 
相關問題