0

I have this kind of menu: "Level 1" has menu item "Level 2", which links to the page with "cat1" url. Then, I have node which have aliases "cat1/[nid]", hence, in my opinion, menu block (provided by "menu block" module) should appear. But it doesn't. Why?

If you haven't worked with menu block module and not familliar with it, then how can I force to show "Level 1 -> Level 2" menu part if a node with alias "cat1/[nid]" is loaded?

2

Solved that! Inspecting the code of Menu Block cleared it out for me that this module doesn't work with URLs. What a pity!

But:

There is a completely awesome bunch of modules: Context withContext:Menu Block which make it possible. Context menu block modules make Menu Block module being aware of context. Also this page may be useful.

But still, if you have better solutions, please write it here.

  • Another solution I have used, which may or may not have benefits over yours, is to manually set the menu tree for the menu being displayed by the menu block module. I will post full answer here. – user34185 Apr 30 '15 at 10:51
  • One note - your link to metachunk.com/blog/setting-active-menu-path-drupal-7-0 appears broken at the moment, but it's possible the solution is similar to mine. – user34185 Apr 30 '15 at 10:59
0

I had similar issue, and I added a hook_preprocess_page() to my template.php, in order to manually set the current path for the menu that is being displayed by Menu Block - so, as with your example, we can set the URL to the node's parent alias.

An example:

$path = current_path();
$path_alias = drupal_get_path_alias($path);

if(strpos($path_alias,'my-parent-alias')!==false) {
    menu_tree_set_path('menu-machine-name', drupal_get_normal_path('my-parent-alias'));
}

Now when you visit your node, you will see the menu's within the context of the node's parent alias.

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.