4umak
4umak

Reputation: 3

menu item activation in drupal 7

I want to do something like this in page.tpl.php:

<?php
$main_menu_tree = menu_tree('main-menu');
    [ get current page/path ]
    [ IF we are on page1 THEN set menu item "item1" active ]
    print drupal_render($main_menu_tree);
    ?>

how can i do that?

Upvotes: 0

Views: 661

Answers (1)

Clive
Clive

Reputation: 36957

I think you're looking for menu_set_active_item():

if ($_GET['q'] == 'page1') {
  menu_set_active_item('item1');
}

Doing the in page.tpl.php will probably be too late in the process for this to actually work. The docs page recommends doing it early on in the page build, for example in hook_init().

Upvotes: 1

Related Questions