This has stumped me for a while now.

I have my code creating all my Menu Items, but I cant find out how I create the menu containers and assign them to a region through code.

Currently I create the 'menu-container' through the admin and use the following code to add the menu item:

$items['path/%'] = array(
'title' => 'menu item title',
'description' => 'Menu item description.',
'page callback' => 'my function',
'access arguments' => array('permissions'),
'page arguments' => array(1),
'file' => 'modulename.admin.inc',
'menu_name' => 'menu-container',
);

What am I missing to create the 'menu-container' object and assign it to a region?
No doubt something insanely simple I have missed.

Comments

Raf’s picture

So if I understand correct, you want to make a new menu (like Primary Links, Secondary Links, etc, but one yet different from those) and want to know how to use a variable like $primary_links or $secondary_links for it in page.tpl.php?

nakeddesign’s picture

Yes, exactly as you say - I guess the equivilant of the using the admin to "add menu" followed by assign block to region.

Raf’s picture

You'll want to use a combination of menu_load() and a preprocess function (check template_preprocess_page out)

nakeddesign’s picture

Thanks - I think that will help me display the menu but how do I create the menu programatically (or is that what menu_load does?)

Raf’s picture

If you've achieved in getting it listed in the menus menu, you should be able to call it with menu_load. Give it a try for primary_links, to see how it works ;)

nakeddesign’s picture

"If you've achieved in getting it listed in the menus menu" - This is the bit I cant find out how to do. I'm sure it will be possible, but I cant seem to find it documented anywhere.

tomas.teicher’s picture

try documentation. Look this link
http://api.drupal.org/api/drupal/modules--menu--menu.module/function/men...

Edit:// sory, this is only for D7

nakeddesign’s picture

I'm guessing this is not possible in D6 then

md2’s picture

Hi nakeddesign,

From what I gather you want to create the menu container that holds the menu items, your creating the menu items in code and need somewhere for them to sit.
You could create this through the Drupal admin pages, but I'm assuming you want to do this in code.

I think the solution is that you need to write an install function to create the menu containers in your DB - see http://api.drupal.org/api/drupal/modules--menu--menu.install/function/me... as an example

Once your menu container is in the DB it should automatically create a block, which can be assigned to any region you wish through code or via admin pages.

Hope this helps.