This question already has an answer here:

I have been struggling/failing for the last day to try find a way that I can add a flag/marker to the Drupal menu links that I can examine within the menu TWIG template to modify the link such that it becomes plain text instead of a menu link.

I am not using any menu modules, standard Drupal Menu with CSS to provide the drop down functionality and styling.

What I need is to be able to output a menu item as shown in the screen shot, specifically the 'Sell your property' & 'Essential Services' items which are unlinked headers.

enter image description here

Initially I attempted to use the contributed module menu item extras (https://www.drupal.org/project/menu_item_extras) which works fine from a menu management plugin point of view but then they change the markup way too much and it actually breaks the drop down functionality, so I cannot use it.

I then tried a second module which seemed simpler, i.e. Menu link content fields (https://www.drupal.org/project/menu_link_content_fields).

This module has some strange behaviour in that it makes the menu links fieldable. I can add a new field but after adding a field, it does not appear under the Manage Fields tab, and in the twig template the new field is un-available in the menu item object (Examined through xDebug)

Also, trying to remove this invisible field at a later stage seems difficult.

Question: How can I easily add some sort of marker to a menu item link to allow me to modify the template output for said link. Or is the re a module that will allow then insertion of HTML markup/plain text instead of a link (Megamenu doesnt seem to allow this)

Also, I cannot seem to find the hook which deals specifically with a sites menu, i.e. the hook that is executed for each menu link. Does one even exist?

I'd like to avoid a hack whereby I put in a unique string into the text of the link and then examine this in the menu twig templates to see if that string exists to know if I need to modify it.

marked as duplicate by leymannx, kiamlaluno Oct 9 '18 at 19:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • You need to enable Twig Debugging first: drupal.org/docs/8/theming/twig/debugging-twig-templates This will help you understand which files need to be overridden – Ismail Cherri Oct 9 '18 at 10:45
  • I have got twig debugging installed and enabled. Templating is not my issue. – John Cogan Oct 9 '18 at 10:51
  • The attached duplicate answer sdolved part of the problem and allowed me to at least change styling based on the route:<nolink> – John Cogan Oct 11 '18 at 9:59

The module Special menu items allows you this, even some control over the HTML output.

This is now in Drupal core (although Docs need some updating):

This features is in core for >=8.2.0. Create menu without link by entering route: <nolink>.

That is, you enter into Link:


and select:

Show as expanded

if you need it for drop-downs.

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