Last active
December 17, 2015 23:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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