Skip to content

Instantly share code, notes, and snippets.

@labboy0276
Last active August 29, 2015 14:06
Show Gist options
  • Save labboy0276/8a7c6b382ee89376415f to your computer and use it in GitHub Desktop.
Save labboy0276/8a7c6b382ee89376415f to your computer and use it in GitHub Desktop.
Drupal Front Page Anchor Tags - Bootstrap
function <YOURTHEME>_links__system_main_menu($variables) {
$menu = '';
// Adds heading class
$menu .= '<h2 class="';
foreach ($variables['heading']['class'] as $key) {
$menu .= $key . ' ';
}
$menu .= '">Main menu</h2>';
// Adds UL classes
$menu .= '<ul class="';
foreach ($variables['attributes']['class'] as $key) {
$menu .= $key . ' ';
}
$menu .= '" role="menubar">';
// Adds LI classes
foreach ($variables['links'] as $key => $value) {
if (isset($value["#title"])) {
$menu .= '<li class="mid-' . $key . ' ';
if (isset($value['#attributes']['class'][0])) {
$menu .= $value['#attributes']['class'][0];
}
$menu .= '" role="presentation">';
switch ($value['#title']) {
case 'About':
$menu .= '<a href="#about"';
break;
case 'Home':
$menu .= '<a href="/"';
break;
// WE CAN ADD OTHER CASES HERE LIKE ABOVE
}
if (isset($value['#original_link']['options']['attributes']['class'])) {
$menu .= ' class="';
foreach ($value['#original_link']['options']['attributes']['class'] as $class) {
$menu .= $class . ' ';
}
$menu .= '"';
}
$menu .= ' role="menuitem">' . $value['#title'] . '</a></li>';
}
}
return $menu;
}
@andrewmallis
Copy link

u should use the l() function to output links:
https://api.drupal.org/api/drupal/includes%21common.inc/function/l/7

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