【发布时间】:2015-01-29 16:55:00
【问题描述】:
我的菜单需要改进。我需要在父菜单项上有一个类,但是通过我的递归,它不起作用。
这是(部分)我的菜单:
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 %}
有了这个,我的菜单就可以工作了。
当我单击“项目”时,一切正常,两个项目都在视图中。但是当我点击一个项目时,我希望页面显示,但它没有,它确实重建了我的菜单,并将所需的类添加到子元素:
{% if child.selected %}selected parent_{{forloop.counter}}{% endif %}
很明显,因为我猜它现在是一个孩子,但是如何防止这种情况呢?对于第一个菜单项,我只需要该类。
【问题讨论】:
标签: css django menu django-cms