1

I want to explain this as simple as possible...

I have a main navigation placed into the main_navigation block in my site and I want to add a sidebar menu if the CURRENT main_navigation page has child menus...

For example:

  1. My main navigation is: Home | About | Services | Blog | Contact Us
  2. I added Request Quote page/form as a child of Contact Us
  3. so when I am in Contact Us page, I want to show Request Quote in the sidebar but don't show it if I am in About or Services

I saw this question but can't duplicate it

Get menu link siblings

Any help is welcome!

1

Use the Menu Block module, create a new Menu Block using the Primary Navigation, starting at Level 2.

This will only show the children of the current parent menu item you are in.

3
  • Menu Block module is not available for Drupal 8... I already created a secondary_menu block with starting at level 2 but it's showing for all main active menus... – Masterful Jun 16 '16 at 18:38
  • 1
    Ah, I didn't see the tiny 8 tag on the post. Haven't worked with D8 yet, sorry. – Travis Johnston Jun 16 '16 at 18:43
  • 1
    that's ok, you're trying to help, I know how to do it in drupal 7 but a little harder in 8... – Masterful Jun 16 '16 at 19:02
0

I was able to solved the issue by doing a few things:

  1. I downloaded & enabled this module: https://github.com/studgate/expanded_menu_block, a temporary Drupal 8 port of menu_block
  2. Placing a new block in the left_sidebar region, I selected the main navigation menu
  3. configure the block to have 'Initial menu level 3' and 'unlimited' menu levels to display
  4. Clear cache and make sure your child menus are showing properly in the sidebar

enter image description here If other child menu items are showing in the sidebar, go to Edit Menu page and edit each Parent Main Navigation menu and uncheck 'Show As Expanded'

If there is even an easier way, just comment...

0

Add this block core\modules\system\src\Plugin\Block\SystemMenuBlock.php

if ($level > 1) { if (count($parameters->activeTrail) >= $level) { // Active trail array is child-first. Reverse it, and pull the new menu // root based on the parent of the configured start level.

   $menu_trail_ids = array_reverse(array_values($parameters->activeTrail));
    $menu_root = $menu_trail_ids[$level - 1];

    $parameters->setRoot($menu_root)->setMinDepth(1);
    if ($depth > 0) {
      $parameters->setMaxDepth(min($level - 1 + $depth - 1, $this->menuTree->maxDepth()));
    }
  }

  else {
    return array();
  }
}

Configure level 2 or above level in block layout. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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