Different menu for homepage not working properly

Created on 21 June 2023, over 1 year ago

I'm trying to use a different navigation menu (horizonal and off canvas) for the homepage than on other pages. I was looking at the examples in the api file and used the following code:

function my_module_responsive_menu_off_canvas_menu_names_alter(&$menus) {
  if (\Drupal::service('path.matcher')->isFrontPage()) {
    $menus = 'frontpage-menu';
  }
}

However, this changes the off canvas menu on ALL pages, not just the homepage.

I also used the following code to change the horizontal menu and that's not giving any issues, it seems to work fine.

function my_module_responsive_menu_horizontal_menu_name_alter(&$menu_name) {
  if (\Drupal::service('path.matcher')->isFrontPage()) {
    $menu_name = 'frontpage-menu';
  }
}

So it's just the off canvas menu that's giving problems. Am I missing something or doing something wrong? I'm using the module on a Drupal 10 website, but also tested it on a Drupal 9 website which gave the same issue.

💬 Support request
Status

Active

Version

4.4

Component

Code

Created by

🇳🇱Netherlands marcom2021

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024