2

drupal 8: Theme used "bartik".

If user is logged in, the active menu item has an <a> - tag, if not the tag is missing.

Is this the expected drupal behavior? btw. the same happens on the language switcher block.

How can i output the a-href tag for anonymous users? This would make theming menus much easier. Thx for any help or pointing me into the right direction

markup for anonymous user

    <ul class="clearfix menu">
.....
<li class="menu-item menu-item--active-trail">
    c
</li>

markup for admin user

<ul class="clearfix menu">
......
<li class="menu-item menu-item--active-trail">
    <a href="/drupal-8.0.3-clean/node/3" data-drupal-link-system-path="node/3" class="is-active">c</a>
</li>

screenshot

2
  • I don't seem to get the same results as you. It works as expected on my side. Does it only do that on that particular node, or are all nodes the same? Have you modified the menu template at all?
    – Janey
    Mar 1, 2016 at 14:40
  • its the same behavior on all nodes. the example above is a clean install with only devel modul enabled....but i get this behavior on all other drupal installations on my localhost
    – wuwu
    Mar 1, 2016 at 14:44

1 Answer 1

0

I fixed this issue by overriding menu.html.twig. You could override menu--main.html.twig instead, if you just want to target the main menu:

menu.html.twig

<li{{ item.attributes.addClass(classes) }}>
  ##REPLACE THIS LINE:## {{ link(item.title, item.url) }}
  ##WITH THIS LINE:## <a data-drupal-link-system-path="{{ item.url }}" title="{{ item.title }}" href="{{ item.url }}">{{ item.title }}</a>
  {% if item.below %}
    {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
  {% endif %}
</li>

I submitted a bug report here: https://www.drupal.org/node/2695619

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.