Django CMS菜单,如何只为父母设置一个班级?

时间:2014-12-01 16:17:14

标签: css django menu django-cms

我的菜单需要一些工作。我需要在父菜单项上有一个类,但是我的递归,它不起作用。

这是我菜单的一部分:

Home
    Teachers (id teachers)
        Contact
        Info
        Projects
          myproject
          yourproject

我从"老师"开始像这样:

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

这是我的老师_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 %}

显而易见,因为现在我猜它是一个孩子,但如何防止这种情况?我只需要第一个菜单项的那个类。

1 个答案:

答案 0 :(得分: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 %}

因此额外的模板负责子菜单。有了一些造型,它现在有效。