【问题标题】:Add menu class in Drupal8在 Drupal8 中添加菜单类
【发布时间】:2017-09-08 10:11:00
【问题描述】:

我安装了链接属性模块以在菜单项中添加类,但它没有显示已添加菜单的属性,即 Drupal8 菜单中默认出现的菜单。

如何在 Drupal 默认菜单中添加类,即我的帐户、登录和注销菜单。

【问题讨论】:

    标签: drupal-8


    【解决方案1】:

    您可以将菜单模板复制到您的主题中并以这种方式添加类吗?

    您可以在这里找到导航模板core/themes/classy/templates/navigation,登录用户的导航模板是links.html.twig。如果您启用 twig 调试,您将能够看到正在使用的模板有一个关于如何做到这一点的指南here。然后您所要做的就是将该模板复制到您的主题中并将其修改为您想要的方式。下面的例子:-

    {% if links -%}
      {%- if heading -%}
        {%- if heading.level -%}
          <{{ heading.level }}{{ heading.attributes }}>{{ heading.text }}</{{ heading.level }}>
        {%- else -%}
          <h2{{ heading.attributes }}>{{ heading.text }}</h2>
        {%- endif -%}
      {%- endif -%}
      <ul{{ attributes.addClass('my-class') }}>
        {%- for item in links -%}
          <li{{ item.attributes }}>
            {%- if item.link -%}
              {{ item.link }}
            {%- elseif item.text_attributes -%}
              <span{{ item.text_attributes }}>{{ item.text }}</span>
            {%- else -%}
              {{ item.text }}
            {%- endif -%}
          </li>
        {%- endfor -%}
      </ul>
    {%- endif %}
    

    【讨论】:

    • 这个解决方案很好......但我也想要 UI 界面,我可以稍后更改类......
    • 可以做到,但不能没有自定义代码,您想即时更改课程的原因是什么?或许能想出另一个解决方案。
    • 我只希望如果有人想直接更改类,那么不需要去代码。如果我把这项工作交给设计师,那么他将无法找到代码..
    猜你喜欢
    • 1970-01-01
    • 2011-06-19
    • 2019-05-12
    • 2016-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多