Questions tagged as ['navigation']

Use it for questions about navigation menus and links used in a site.
Score: -1
MetalBearSolid avatar
anchor menu description under each menu in menu.html.twig
br flag

I am currently displaying the Menu "description" underneath each link using menu.html.twig. by doing this:

{% if item.original_link.getDescription %}
  <span class="navigation__link-description">{{ item.original_link.getDescription() }}</span>
{% endif %}

The issue is that it's not anchored with the URL due to it being outside {{ link(item.title, item.url) }}. Does anyone know what I ne ...

Score: 0
Menu item extras field in page.html.twig
cn flag

I need a background image per menu item. For this I'm using menu_item_extras. I added an image field to menu items. This field I'd like to use in page.html.twig.

How can I use this field in this template?

Score: 0
List all the nodes with the same menu parent ID
pt flag

I have the following menu in my system.


The parent menu-link connects to a node whose ID is 58. All the sub menu-links have a parent ID equal to 58.

I need to find the main and the sub-menus using 58, but I have been unsuccessful at locating the a table that contains that information.

How can I list the nodes that share a particular menu ID?

Score: 0
stckvrw avatar
Hash in menu item url are removed when displaying the menu on a page
gb flag

If a menu item has a submenu and I specify the hash symbol (#) in the Link field of such parent menu item in the admin panel, I receive empty url at the frontend and therefore if click by such link, I follow to the homepage.

Even if I use in my menu--main.html.twig template the code like

{% set menu_item_url = item.url %}
{% if menu_item_url == '' %}
{% set menu_item_url = '#' %}
{% endif %}
<a  ...
Score: 0
Bradley avatar
The "is-active" class is added to the main-menu links only when the site is accessed by an anonymous user
kr flag

I use this simple template (menu--main.html.twig) to render the main menu I created.

    {% for item in items %}
        {{ link(item.title, item.url) }}
        {% if item.below is not empty %}
            <div class='submenu'>
                {% for subitem in item.below %}
                    {{ link(subitem.title, subitem.url) }}
                {% endfor %}
Score: 1
shelane avatar
Is there a way to disable the <nolink> option for menu links?
cn flag

For our unified Drupal platform, we require all of our sites main menu items to be a page and any sub-pages to show a path following the parent menu item. So if "About Us" (with a path of /about-us) is a top level menu item, it must be a page. And the page "History" under that will have a path of /about-us/history. "About Us" cannot be a <nolink> with History as a child. How can I prevent users ...

Score: 1
Interlated avatar
How do I add items from from the user module to a menu?
km flag

How do I add the core user module links such as My account and Log out to another menu?

Score: 0
shelane avatar
How do you batch process a path alias change for nodes that includes a menu placement change?
cn flag

We have an annual reporting sites that contains approximately 200 nodes each year. When the next year's reports are complete, all of the current year's nodes move to a path like /archives/fy2020/*. Not only do their paths change, but the menu items change as well to 1) create a new entry year 2) move menu items to the new entry year as the parent.

I am looking at what type of batch process I can used to ...

Score: 0
hotwebmatter avatar
Template preprocess to generate Font Awesome markup for menu links
nr flag

In Drupal 9, I need the ability to prepend Font Awesome icons to menu links.

I have attached Font Awesome 5 JS and CSS assets to my theme via *.libraries.yml.

If I open a menu link in the DOM inspector and edit the markup of a link from this:

<ul class="clearfix nav">
  <li class="nav-item">
    <a href="#comments" class="nav-link nav-link-comments">Comments</a>
&l ...
Score: 1
Rubix05 avatar
Dynamically load the menu items created from the links.task.yml file
cn flag

I need to programmatically load the links that are generated from my_module.links.task.yml on another page.

My exact use case is that I have a set of links that are shown when viewing my node page. The links will be shown and hidden based on the current user's access and the access control is handled through the options in the my_module.routing.yml file.

I need to create a separate page that displa ...

Score: 0
Monster971 avatar
How to make a vertical menu properly?
id flag

Good morning all,

Today I would like to ask a simple question about the menus. How do you make a clean sidebar that takes up the entire length of the page? In general, the themes offer only natively horizontal menus that occupy the entire width.

To have a sidebar, you must put the menu in a block side position and make the necessary adjustments with CSS?

Score: 0
stckvrw avatar
How to receive menu items in Twig template as array/object?
gb flag

I need to receive (for example by menu machine name) and operate menu items data to use it in Drupal Twig template like:

{% for item in items %}
    <li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}

But I can't find an information on how to do that.

The only thing I've found is like

{% import _self as menus %}
{{ menus.menu_links(items ...
Score: 1
ilechcod avatar
Restrict Menu Item Visibility by Permissions
in flag

I have a module-generated menu (using yaml file) with 5 menu items. My requirements don't allow me to restrict menu item visibility by role because roles can be dynamically added. So I have to do this using permissions only.

What I've tried
(1) Restricting menu item access using route permissions - this shows a page forbidden but still allows the restricted menu item to be visible

Please see my actual fi ...

Score: 0
Set local actions - disabled/inactive
cn flag

I am currently searching for a possibility to set an action to "inactive" depending on something. I have found the hook_menu_local_actions_alter(&$local_actions), but do not know how I could use it to set a task to disabled/inactive.

What I have tried for now is:

function my_module_menu_local_actions_alter(&$local_actions) {
  $local_actions['entity.my_module.add_form']['options']['attribute ...
Score: 0
steevee666 avatar
How to replace the default page and tab of profiles in the user account?
in flag

I installed the "Profile" module on my "Drupal 9" website. When I create a profile type, the module automatically creates a tab in the user account for each profile type.

For my profile type "projects" the user account tab displays the page for this profile type, with this path :


Here is the view added by the module :

enter image description here

Here are the tabs created in the user account :

enter image description here

I created ...

Score: -1
steevee666 avatar
How can I re-organize the user account tabs?
in flag

I have a Drupal 9 site. I can't find how to rearrange or rename the user account tabs.

How can I re-organize the user account tabs?


Score: 0
Usman Manzoor avatar
Translating Menu Item Programmatically?
pk flag

I have been trying to translate menu items programmatically but upon saving it just adds the english field value to all my translations. Below is the code I am trying to execute:

 if ($entity->hasTranslation($language->getId())) {
      //For update
    try {
      $entity->addTranslation($language->getId(), ['title' =&gt ...