2016-03-05 68 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 %} 
相关问题