How can I simply add "#" as a menu link in Drupal 8? I want to have:

<a href="#" ... output as a menu link.

Do I have to define my own route token akin to <nolink> and write a custom LinkGenerator class to handle that case?


elseif ($url->isRouted() && $url->getRouteName() === '<nolink>') {
      $generated_link = new GeneratedNoLink();
elseif ($url->isRouted() && $url->getRouteName() === '<hashonly>') {
      $generated_link = new GeneratedLink();
      $attributes['href']= "#";

Or is there an easier place to do this without disrupting the render pipeline?


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.

Browse other questions tagged or ask your own question.