Create a gist now

Instantly share code, notes, and snippets.

Embed
function themename_menu_link(&$variables) {
$element = $variables['element'];
$sub_menu = '';
$element['#attributes']['data-menu-parent'] = $element['#original_link']['menu_name'] . '-' . $element['#original_link']['depth'];
if ($element['#below']) {
$sub_menu = drupal_render($element['#below']);
}
$output = l($element['#title'], $element['#href'], $element['#localized_options']);
return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}
function themename_preprocess_menu_tree(&$variables) {
$tree = new DOMDocument();
@$tree->loadHTML($variables['tree']);
$links = $tree->getElementsByTagname('li');
$parent = '';
foreach ($links as $link) {
$parent = $link->getAttribute('data-menu-parent');
break;
}
$variables['menu_parent'] = $parent;
}
function themename_menu_tree(&$variables) {
return '<ul class="menu ' . $variables['menu_parent'] . '">' . $variables['tree'] . '</ul>';
}
@knibals

This comment has been minimized.

Show comment
Hide comment
@knibals

knibals May 20, 2014

Thx for the good work! I just wrapped the content in an array:

$element['#attributes']['data-menu-parent'] = array($element['#original_link']['menu_name'] . '-' . $element['#original_link']['depth']);

knibals commented May 20, 2014

Thx for the good work! I just wrapped the content in an array:

$element['#attributes']['data-menu-parent'] = array($element['#original_link']['menu_name'] . '-' . $element['#original_link']['depth']);
@lmeurs

This comment has been minimized.

Show comment
Hide comment
@lmeurs

lmeurs Oct 19, 2014

Thanks, great gist!

lmeurs commented Oct 19, 2014

Thanks, great gist!

@shahmeerarshad

This comment has been minimized.

Show comment
Hide comment
@shahmeerarshad

shahmeerarshad Aug 18, 2015

im a newbie to drupal
all i want to ask is what should i print in my page.tpl.php file in order to print the menu generated by the above code

im a newbie to drupal
all i want to ask is what should i print in my page.tpl.php file in order to print the menu generated by the above code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment