Hello all. I am not sure why this function menu_tree_output() cannot be themable. The themable menu functions target the menu items or the html wrapper (

    ).
    So what if there is a custom menu with pipes in between the the
  • 's? Well using the themeable functions you could not do anything.

    With more websites using complicated designs with menu structures I am not sure why no one has requested this before.

    Here is a link to the code I had to use to implement custom menues:

    <?php
    Here is the html that calls the custom
    function:
            <
    div id="header">
                <
    h1>
                    <
    a href="/">Air Phaser Environmental</a>
                </
    h1>
                <?
    php
                           
    //this is added to build a custom theme for the menu
                           
    print air_phaser_menu_tree($menu_name = 'primary-links');
                           
    ?>

    -------------------------------------------------------------
    Here is the custom functions in the template.php:
    /**
    * This is to override the drupal menus so we can build new ones.
    * I have taken the drupal menu functions and re-built them
    */
    function air_phaser_menu_tree($menu_name = 'navigation') {
    static $menu_output = array();
    if (!isset($menu_output[$menu_name])) {
    //call drupal funtion
    $tree = menu_tree_page_data($menu_name);
    //call custom function sending the menu name so we can add cutstom ids for the menu
    $menu_output[$menu_name] = air_phaser_menu_tree_output($tree, $menu_name);
    }
    return $menu_output[$menu_name];
    }

    //this function has be rewritten to get the name of the menu for different styling
    function air_phaser_menu_tree_output($tree, $menu_name) {
    //clear output
    $output = '';
    $items = array();
    // Pull out just the menu items we are going to render so that we
    // get an accurate count for the first/last classes.
    foreach ($tree as $data) {
    if (!$data['link']['hidden']) {
    $items[] = $data;
    }
    }
    //count menu items
    $num_items = count($items);
    //loop through the items
    foreach ($items as $i => $data) {
    $extra_class = NULL;
    if ($i == 0) {
    $extra_class = 'first';
    }else{
    //adding my pipes here.
    $output .= "

  • |
  • ";
    }
    if ($i == $num_items - 1) {
    $extra_class = 'last';
    }

    $link = theme('menu_item_link', $data['link']);
    if ($data['below']) {
    $output .= theme('menu_item', $link, $data['link']['has_children'], menu_tree_output($data['below']), $data['link']['in_active_trail'], $extra_class);
    }
    else {
    $output .= theme('menu_item', $link, $data['link']['has_children'], '', $data['link']['in_active_trail'], $extra_class);
    }

    }
    //this connects to the custom themeing function based on the menu type
    //if primary
    if($menu_name == "primary-links"){
    return '

    ';
    }elseif($menu_name == "secondary-links"){
    return '

      '. $output .'

    ';
    }else{
    //call theme function override for normal menues
    return $output ? theme('menu_tree', $output) : '';
    }
    }

    ?>

Comments

Status:Active» Postponed (maintainer needs more info)

Thanks for sharing!

But why not create a documentation page (you've done it before) ?

Or did you want to provide a patch for core?

- Arie

Hello,
I think this function should be a themable function instead of having to rewrite the menu_tree_output() output function.
I am not sure how to rewrite this function to be themeable for a patch.
The issues I have found with this function is that if a user put something other than the Primary Links or Secondary Links, they will have to go into the database in this table 'menu_links' to get the menu name.

In drupal 5 you could just pass the menu ID and have your menu output function.

As a themer-programmer this will make the end result easier to achieve.

Here is an example with 3 custom menus (Primary, Secondary, and Footer)
http://airphaser.katanamite.com/content/applications (still in dev mode)

chris

Version:6.9» 7.x-dev
Category:support» feature

Right, that would make this a feature request. Changing category and version (new features are always developed in HEAD and then back ported to earlier versions)

- Arie

Version:7.x-dev» 6.9

I thought this was posted as a feature request?

Version:6.9» 7.x-dev
Status:Postponed (maintainer needs more info)» Active

New features, as Arie mentioned are developed for 7.x. There are menu_link, menu_item and menu_tree theme but I can see that the way menu_tree_output concats these together might need override, though overriding each menu_item in Drupal 6 might be enough even if quite ardous. The question here is, do we want this to become a drupal_render-able structure? Would make it nice and easy...

I think this is a duplicate of: http://drupal.org/node/283723

Status:Active» Closed (duplicate)