2

I have a custom menu - its a module with html links in the .tpl file, set on the website as a block. I wanted to know is it possible to configure drupal so it dynamically add .current class to those links so I can style it when particular page is being viewed. Thanks for help.

2

If you create a new menu and make it a block then it will set a class called "active" when you are on the current page. You will also get a class called "active-trail" for each parent item. If you want to create something more custom then you can check and see if the url matches the link you are building.

You can see here how the menu is being built to get some ideas:

https://api.drupal.org/api/drupal/includes%21menu.inc/function/menu_tree_output/7

If you want to do something custom then you will need to compare $_GET['q'] to the link that you are building in order to set an active class.

I am pretty sure you can also use theme_item list and the active class will be set:

https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme_item_list/7

| improve this answer | |
0

Also you can use the module menu attributes and at the same time create a custom token that print the class that you need.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.