【问题标题】:How to add a class to a menu item that has children (nested pages) in Django-CMS如何在 Django-CMS 中向具有子项(嵌套页面)的菜单项添加类
【发布时间】: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


【解决方案1】:

{% if child.children %}...{% endif %}

【讨论】:

  • 不知道为什么它现在有效。我早些时候尝试过,但它没有用..非常感谢!
猜你喜欢
  • 1970-01-01
  • 2021-08-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多