【发布时间】:2012-08-11 12:18:09
【问题描述】:
我正在开展一个项目,其中包含嵌套子项的菜单项上有一些特定样式。菜单结构看起来像这样
Home
|
About
|
Services
|_ web design
|_ social marketing
|_ traditional marketing
我在我的模板中使用 {% show_menu 0 100 100 100 "menu.html" %} 并且我的 menu.html 中有以下内容:
{% load menu_tags %}
{% for child in children %}
<li class="{% if child.selected %}active{% endif %}{% if child.sibling %}dropdown{% endif %}">
<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>
{% if child.children %}
<ul>
{% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
</ul>
{% endif %}
</li>
{% endfor %}
我将 {% if child.sibling %}dropdown{% endif %} 放在那里以说明我希望将类添加到何处,但将其定位为 child.sibling 并不是正确的做法。有没有办法像这样{% if child.has_children %}dropdown{% endif %} 来定位特定的下拉菜单?
谢谢
【问题讨论】:
-
{% if child.ancestor %}ancestor{% endif %}做你想做的事吗? -
不,它没有。我尝试了 child.sibling、child.ancestor、child.descendant,但它们都不起作用 - 除了 child.sibling,但它正在将下拉类添加到除 child.selected 项之外的每个菜单项。
标签: django django-cms