[support] tutorial on dynamically generating menu in D5

Metzler, David metzlerd at evergreen.edu
Mon Jul 28 14:44:52 UTC 2008


This is one way, (and in fact the only way in D6).  

It's important to understand in D5 and before that the truly dynamic menus must be in the if (!$may_cache) section of hook menu. 

In D5 this is possible: 
  function mymodule_menu($may_cache) { 
     if ($may_cache ) {
         $items[] = array(....... Normal static menus go here 
     } else { 
         if (some conditional logic here)  {
            $items[] = array (....
         }
         $items = array( path => path_generated_by_func )
     } 
  }

But it isn't possible in drupal 6, so not really advised.  In d6: 

   function (mymodule_menu) { 
      $menu['path/to/menu'] = array( 
         ..... Other menu items ommited for clarity. 
        'access callback' => 'mymodule_function',
        'access arguments' => array( 'myarg1')
        )
   } 
   
   function (mymodule_menu) { 
      .... Function that returns false or tru based on whether the menu should show up .... 
   }


-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On Behalf Of Florent JOUSSEAUME
Sent: Monday, July 28, 2008 7:08 AM
To: support at drupal.org
Subject: Re: [support] tutorial on dynamically generating menu in D5

For your example, this is not a switch, but 2 modules with differents ACL. The block 'login' is displayed for 'Anonymous' and the menu is displayed for 'Authenticated user' (block Navigation).

For the element's visibility in the menu, this is with the user_access method defined in the function 'hook_menu' for each module.

Florent JOUSSEAUME,

Ivan Sergio Borgonovo a écrit :
> I've to dynamically generate the menu and I've the feeling that just 
> adding items in menu_hook and trial&error won't take me far reasonably 
> efficiently.
>
> eg. I'm interested in obtaining effects similar to "Login" turning 
> into "My account" even for menu created from the admin interface.
>
> I'm reading drupal source but I'd hope there is a faster way to get 
> the rough picture and some examples.
>
> thanks
>
>   


--
[ Drupal support list | http://lists.drupal.org/ ]


More information about the support mailing list