I've created couple of blocks from the Drupal UI.

These blocks has unsorted list with links to the other pages.

They act like a sub menus located into the sidebar region and visible to specific pages.

Here's an example for a block called fruits that have a couple of links:

  • Apple
  • Orange
  • Mango

The Drupal menu system or Superfish module generates active class on the links based on the URL location. How can I do that with these blocks, so let's say a user clicks on the link Apple and when the new page loads, the Apple link will have a active class, so it will look like this:

<li><a href="/apple" class="active">Apple</a></li>

I want this, so I can set a CSS for active link.

1 Answer 1


It needs to be done with PHP. If you use the l() function to generate your links, they will automatically get the active class if you are the page to which the link is linked to. To do this you would need to enable the PHP filter, but this filter is both recommended against, as well as non-existent in Drupal 8, so it would be better to create a block through code and use that instead of enabling the PHP filter.

  • Thank you for your answer, Jaypan. Yes, I thought about that and I know how to create a custom block with a module, but unfortunately it won't be easy for builders to change the links and add another blocks without using a code. Jun 12, 2017 at 11:49
  • Well, I will use the menu system from the Drupal UI to create these blocks, but I'm marking your answer, 'cos it's very useful. Jun 12, 2017 at 12:07
  • The menu system will automatically pick up the active link
    – Jaypan
    Jun 12, 2017 at 12:08
  • Yes, that's right.:) Jun 12, 2017 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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