Skip to content

Instantly share code, notes, and snippets.

@xavicolomer
Last active August 3, 2016 09:15
Show Gist options
  • Save xavicolomer/8290643 to your computer and use it in GitHub Desktop.
Save xavicolomer/8290643 to your computer and use it in GitHub Desktop.
Drupal n-level submenus working with Zurb Foundation 5
/**
* This snippet should replace the old 'zurb_foundation_links__system_main_menu' found on template.php inside the zurb-foundation theme
/*
/**
* Implements theme_links() targeting the main menu specifically
* Outputs Foundation Nav bar http://foundation.zurb.com/docs/navigation.php
*
*/
function zurb_foundation_links__system_main_menu($vars) {
// Get all the main menu links
$menu_links = menu_tree_output(menu_tree_all_data('main-menu'));
// Initialize some variables to prevent errors
$output = '';
$output .= recursive_menu($menu_links);
return '<ul class="left">' . $output . '</ul>';
}
function recursive_menu($menu_links)
{
$output = '';
$sub_menu = '';
foreach ($menu_links as $key => $link) {
if (!empty($link['#href'])) {
$classes = 'class="'.(!empty($link['#below']) ? $link['#attributes']['class'][] = 'has-dropdown' : '').'"';
$output .= '<li ' . $classes . '>' . l($link['#title'], $link['#href']);
if (!empty($link['#below']))
{
$output .= !empty($link['#below']) ? '<ul class="dropdown">' . recursive_menu($link['#below']) . '</ul>' : '';
}
$output .= '</li>';
}
}
unset($sub_menu);
$sub_menu = '';
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment