Skip to content

Instantly share code, notes, and snippets.

@aschiwi
Last active December 17, 2015 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aschiwi/5690860 to your computer and use it in GitHub Desktop.
Save aschiwi/5690860 to your computer and use it in GitHub Desktop.
How to add classes and ids to main and secondary menu in Drupal 8. Add this to your theme's .theme file (in this case it's busy.theme). The .theme file is called template.php in Drupal 7.
/**
* Implements hook_preprocess_HOOK() for page.tpl.php
*/
function busy_preprocess_page(&$variables) {
// Pass the main menu and secondary menu to the template as render arrays.
if (!empty($variables['main_menu'])) {
$variables['main_menu']['#attributes']['id'] = 'main-menu';
$variables['main_menu']['#attributes']['class'] = array('links', 'clearfix');
}
if (!empty($variables['secondary_menu'])) {
$variables['secondary_menu']['#attributes']['id'] = 'secondary-menu';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment