[英]Drupal 8.x - Beginner - Identify the id or hostname of the block, menu, or other twig template and use it in class naming
I use the Zen theme for drupal 8.x. 我将Zen主题用于drupal8.x。
I need to customize the menus so that they have the machine name or element ids that surrounds it. 我需要自定义菜单,以便它们具有包围它的机器名称或元素ID。 This example is how I intend it to stay:
此示例是我打算如何保留的示例:
<nav role="navigation" aria-labelledby="block-uni-theme-2018-account-menu-menu" id="block-uni-theme-2018-account-menu" class="contextual-region c-navigation-account c-navigation">
<h2 class="visually-hidden" id="block-uni-theme-2018-account-menu-menu">User account menu</h2>
<!-- THEME DEBUG -->
<!-- THEME HOOK: 'menu__account' -->
<!-- FILE NAME SUGGESTIONS:
* menu--account.html.twig
x menu.html.twig
-->
<!-- BEGIN OUTPUT from 'themes/custom/uni_theme_2018/templates/navigation/menu.html.twig' -->
<ul class="c-menu-account c-menu c-navigation-account__menu">...</ul>
<!-- END OUTPUT from 'themes/custom/uni_theme_2018/templates/navigation/menu.html.twig' -->
</nav>
Files I'm using: https://gist.github.com/onaSousa/488ab9349f15bd039c66bc663d43ba04 I do not know how to use the "account" in my menu file. 我正在使用的文件: https : //gist.github.com/onaSousa/488ab9349f15bd039c66bc663d43ba04我不知道如何在菜单文件中使用“帐户”。
In the "menu.html.twig" template the default variable (menu_name) can not be used directly inside the function {% macro %} so we must set the variables together with the parameters to be accessible. 在“ menu.html.twig”模板中,默认变量(menu_name)不能直接在函数{%macro%}内部使用,因此我们必须将变量与参数一起设置为可访问的。
Before: 之前:
{{ menus.menu_links(items, attributes, 0) }} {{menus.menu_links(items,attribute,0)}}
{% macro menu_links(items, attributes, menu_level) %} {%宏menu_links(项目,属性,菜单级别)%}
After: 后:
{{ menus.menu_links(menu_name, items, attributes, 0) }} {{menus.menu_links(菜单名称,项目,属性,0)}}
{% macro menu_links(menu_name, items, attributes, menu_level) %} {%宏menu_links(菜单名称,项目,属性,菜单级别)%}
https://gist.github.com/onaSousa/68ec7fbdc85c30d613d70053dd3e4a2b https://gist.github.com/onaSousa/68ec7fbdc85c30d613d70053dd3e4a2b
<ul class="c-menu-account c-menu--no-levels c-menu">
<li class="c-menu-account__item">
<a href="/user" class="c-menu-account__link" data-drupal-link-system-path="user">Minha conta</a>
</li>
<li class="c-menu-account__item">
<a href="/user/logout" class="c-menu-account__link" data-drupal-link-system-path="user/logout">Sair</a>
</li>
</ul>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.