I'm generating a URL with Url::fromUri() method.

Is there a way to add automatically an "active" class, like D7, if the page is the same of the URL?

Obviously without check manually the value of the generated URL and the page.

1 Answer 1


In the documentation is not present, but on $options array we can simply set "set_active_class" to TRUE (FALSE by default) and then drupal add a "is-active" class to the link:

Url::fromUri('internal:/progetti/selezionati', array('set_active_class' => TRUE)),

I think that this behaviour should be TRUE by default..

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.