Search code examples
menudrupal-7hook

Hook active trail path views Drupal7


I' am trying to make a custom module to set an active trail path to a menu.

I created a views page. The active trail must be to a node or taxonmy term. When I open the pages created by the view the active trail is not active.

I wrote the script here below but it doesn't work, can somebody please help???

function mymodule_views_default_views(&$view, &$display_id, &$args){
  if( $view->name = 'productdetail';)
    {menu_tree_set_path('menu-categorie', 'node/39');
 }
}

Solution

  • I am happy, I have found the answer to my own question. I like to share this answer, and hope, that this although helps others...

    Here the answer: In the view I added a field with the term-id / node ID which is although used for my menu and hide the output and do a rewrite of the output I pasted the following code in text field for rewrite. field_categorie-tid is my reference term from the menu menu_tree_set_path('menu-categorie', 'taxonomy/term/[field_categorie-tid]');. instead of taxonomy term you can although use node/[nid]

    I added in the head section a global field with php and token and put this script:

    Thats all. No hooks or custom scripting in template

    I hope this helps someone else.