2014-12-01 55 views
0

我的菜单需要一些工作。我需要在父菜单项上有一个类,但是使用递归方式,它不起作用。Django CMS菜单,如何为父母设置一个班级?

这是(部分)我的菜单:

Home 
    Teachers (id teachers) 
     Contact 
     Info 
     Projects 
      myproject 
      yourproject 

我开始与 “老师” 是这样的:

{% show_menu_below_id "teqchers" 0 1 0 1 "teachers_menu.html" %} 

这是我teachers_menu.html:

{% load menu_tags %} 
{% for child in children %} 
    <li class="{% if child.selected %}selected parent_{{forloop.counter}}{% endif %} {% if child.sibling %}parent_{{forloop.counter}} {% endif %}"> 
     <a href="{{ child.get_absolute_url }}">{{ child.get_menu_title }}</a> 
     {% if child.children %} 
     <div class="submenu"> 
      <ul> 
       {% show_menu from_level to_level extra_inactive extra_active template "" "" child %} 
      </ul> 
     </div> 
     {% endif %} 
    </li> 
{% endfor %} 

有了这个,我的菜单工作了一下。

当我点击项目,一切都很好,2个项目在视图中。但是当我点击一个项目,我所希望的网页来展示,但它不,它确实重建我的菜单,并添加所需类的子元素:

{% if child.selected %}selected parent_{{forloop.counter}}{% endif %} 

明显,因为它是一个孩子,现在我猜测,但如何防止这一点?我只需要这个类的第一个菜单项。

回答

0

而不是做这个的:

{% show_menu from_level to_level extra_inactive extra_active template "" "" child %} 

我现在又增加了模板是这样的:

{% show_menu from_level to_level extra_inactive extra_active "teachers_submenu.html" "" "" child %} 

而在该模板我现在有:

{% load menu_tags %} 
{% for child in children %} 
    <li class="{% if child.selected %}selected{% endif %}"> 
     <a href="{{ child.get_absolute_url }}">{{ child.get_menu_title }}</a> 
    </li> 
{% endfor %} 

所以额外的模板照顾子菜单。随着一些样式现在可以工作。

相关问题