I have a pretty complicated multi site setup and would like to programmatically embed menus into page.tpl.php. The following works to get the top level menu.

$block = module_invoke('menu', 'block', 'view', 'primary-links');
print $block['content'];

I would like to pass starting level, depth, etc to the module. Is it possible to pass extra arguments?

Comments

bstoppel’s picture

I found another way to do this by using menu_tree_build.

The following code gets that second level and deeper menu items and displays them.

$delta = '';
$my_menu = 'primary_links';

$config = array(
  'delta'       => $delta,
  'menu_name'   => $my_menu,
  'parent_mlid' => 0,
  'title_link'  => 1,
  'admin_title' => '',
  'level'       => 2,
  'follow'      => 0,
  'depth'       => 0,
  'expanded'    => 1,
  'sort'        => 0,
);
$tree = menu_tree_build($config);

print $tree['subject'];
print $tree['content'];

Not sure if this is the right way to go about what I am wanting to accomplish, but it works for me.

bensnyder’s picture

thank you for posting this

Dave Reid’s picture

Status: Active » Fixed

If it works, looks like a fine solution. Thanks for posting.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

webdrips’s picture

Version: 6.x-2.3 » 6.x-2.4
Status: Closed (fixed) » Active

Hi all.

I have in interesting problem: I have a menu block that works beautifully out of box. However, I have a series of page displays in a view, and I was trying the above code in my views template file (before I noticed this post), and the $tree['content'] is an empty string, but $tree['subject'] contains the correct menu title.

(My code is almost identical to the above post, so I did not bother).

Can anyone give me kick in the right direction?

Thanks,

Dan

webdrips’s picture

Seems like my real problem is the $tree[key]['link']['in_active_trail'] will always be FALSE when a view is being used to render a page.

Anybody have any experience overcoming this issue?

Thanks,

Dan

webdrips’s picture

Status: Active » Closed (fixed)

OK I figured it out for anyone interested.

This snippet works on a page generated by the Views module:

  $path = drupal_get_path_alias(check_plain($_GET['q']));
  $pieces = explode("/", $path);
  // Remove the last element of the URI to get the parent
  array_pop($pieces);
  $parent_path = implode('/', $pieces);  
  $menu_item = menu_get_item($parent_path);
  if($parent_path && $menu_item) {
    menu_set_item(NULL, $menu_item);
  }

Place the above code in your view's template file and it should work.