Reply to comment

Drupal 8: Add menu item with anchor link programmatically in .menu.yml

For a Drupal 8 EU Cookie Compliance patch I needed a way to add an anchor link as default menu item programmatically in .menu.yml


example.anchor:
title: "Anchor example"
description: "Scroll to top on the current page"
url: "internal:#top"

See my addition in documentation: https://www.drupal.org/docs/drupal-apis/menu-api/providing-module-define...

Thanks to the comments in https://drupal.stackexchange.com/questions/229376/non-clickable-menu-ite...
and https://drupal.stackexchange.com/questions/280665/how-to-add-a-nolink-me... which helped me a lot to find this solution.

Reply

The content of this field is kept private and will not be shown publicly.

More information about formatting options