Drupal theme preprocess function - primary links and suckerfish menus

Posted by slimcady on Stack Overflow See other posts from Stack Overflow or by slimcady
Published on 2010-05-03T23:28:12Z Indexed on 2010/05/03 23:38 UTC
Read the original article Hit count: 252

Filed under:
|
|

I have a preprocess function that works fine when the menu is single level list. However I would like it to work w/ suckerfish menus. I want to add a class to the top level menu item so that I can style it. This is the code I used for the single level menu:

function cti_flex_preprocess_page(&$vars, $hook) {

// Make a shortcut for the primary links variables
$primary_links = $vars['primary_links'];

// Loop thru the menu, adding a new class for CSS selectors
    $i = 1;

    foreach ($primary_links as $link => $attributes){
        // Append the new class to existing classes for each menu item
        $class = $attributes['attributes']['class'] . " item-$i";

        // Add revised classes back to the primary links temp variable
        $primary_links[$link]['attributes']['class'] = $class;
        $link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';
        $i++;
        } // end the foreach loop

// reset the variable to contain the new markup
$vars['primary_links'] = $primary_links;

}

I've been trying to use the menu_tree() function to no avail, for example:

function cti_flex_preprocess_page(&$vars, $hook) {

// Make a shortcut for the primary links variables
$primary_links = $vars['primary_links'];

// Loop thru the menu, adding a new class for CSS selectors
    $i = 1;

    foreach ($primary_links as $link => $attributes){
        // Append the new class to existing classes for each menu item
        $class = $attributes['attributes']['class'] . " item-$i";

        // Add revised classes back to the primary links temp variable
        $primary_links[$link]['attributes']['class'] = $class;
        $link['title'] = '<span class="hide">' . check_plain($link['title']) . '</span>';
        $i++;
        } // end the foreach loop

// reset the variable to contain the new markup
$vars['primary_links_tree'] = menu_tree(variable_get('menu_primary_links_source', '$primary_links'));

}

Any ideas would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about drupal

Related posts about theme