0

I'm building a function that takes a drupal rendered menu and removes the classes from it so that I can pass it to a jQuery function that'll build a menu from it.

The code i'm using for that is:-

<?php
     $tree = menu_tree_all_data("devel-frus");
     $menu = drupal_render(menu_tree_output($tree));
     $nocss = preg_replace('/class=".*?"/', '', $menu);
     echo($nocss);
?>

However menu_tree_output() seems to be only returning the first level of a six level menu when it should be returning the complete menu.

I've tried dsm()'ing $tree to see if all of the menu items are being returned by menu_tree_all_data() and that's fine, however when I dsm() the output of the menu_tree_output() function only the root and first level are returned in the array.

Am I doing something really obviously wrong here?

0

From what I understand about menu_tree_all_data() you need to supply it a link and depth to give it context (where in the menu tree am I at & how far do I go?). Also drupal_render() expects an argument passed by reference, so there will problems passing the output of function.

// Default to root link w/ a depth 5.
$link = menu_get_item();
$tree = menu_tree_all_data("devel-frus", $link, 5);
$tree_output = menu_tree_output($tree);

// Supply a variable for drupal_render to reference.
$menu = drupal_render($tree_output);

$nocss = preg_replace('/class=".*?"/', '', $menu);
echo($nocss);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.