【问题标题】:Make menu item not clickable in Django CMS在 Django CMS 中使菜单项不可点击
【发布时间】:2013-04-28 00:48:59
【问题描述】:

我有一个使用 Django CMS 运行的 Django 应用程序。 我正在尝试使一个特定的子菜单不可点击。

菜单是这样的:

item1|item2|item3
            sub_item3
            sub_item3

我想要的是除了“item3”菜单项之外的所有东西都是可点击的。

如果知道 item3 本身是一个 Django CMS 页面,它的每个子页面也是如此,我该如何实现这一点?

这背后的想法是防止用户在点击顶部的“item3”菜单项时看到一个空白页面。

【问题讨论】:

    标签: python-2.7 django-cms django-1.4


    【解决方案1】:

    我是这样做的,以防止它在任何地方链接:

    {% load cms_tags menu_tags %}
    {% for child in children %}
    <li>
      {% if child.is_leaf_node %}<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>{% else %}<a href="#">{{ child.get_menu_title }}</a>{% endif %}
      {% if child.children %}
        <ul>
            {% show_menu 0 100 100 100 "menu/top-menu.html" "" "" child %}
        </ul>
        {% endif %}
    </li>
    {% endfor %}
    

    在您的情况下,您可能需要来自 Disable a link using css 的带有类似 CSS 的类

    .active {
       pointer-events: none;
       cursor: default;
    }
    

    【讨论】:

      【解决方案2】:

      好的,我将之前的答案和这些链接https://groups.google.com/forum/?fromgroups=#!topic/django-cms/aS2Ew2mf8XY 和文档https://django-cms.readthedocs.org/en/2.4.0/extending_cms/app_integration.html#how-it-works(导航修饰符)结合起来修复了它。

      from menus.base import Modifier
      from menus.menu_pool import menu_pool
      
      class MyMode(Modifier):
          """
      
          """
          def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
              if post_cut:
                  return nodes
      
              for node in nodes:
                  if node.title == u'Page not clickable':
                      node.no_click = True
      
              return nodes
      
      menu_pool.register_modifier(MyMode)
      

      有了这个模板

      % load cms_tags menu_tags %}
      {% for child in children %}
      <li>
        {% if not child.no_click %}<a href="{{ child.attr.redirect_url|default:child.get_absolute_url }}">{{ child.get_menu_title }}</a>{% else %}<a href="#">{{ child.get_menu_title }}</a>{% endif %}
        {% if child.children %}
          <ul>
              {% show_menu from_level to_level extra_inactive extra_active template "" "" child %}
          </ul>
          {% endif %}
      </li>
      {% endfor %}
      

      在我的主模板(base.html)中,我添加了菜单

      {% show_menu 0 100 100 100 "menu.html" %}
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多