I have a situation where I need to change the active theme based on whether the current entity has a certain taxonomy tag. So when an entity is viewed and tagged with candy, I would like the Candy theme to be activated.

My research has lead me to believe that the easiest way to achieve this is to implement a theme negotiator in a similar way to the example given here.

I am able to switch the active theme based on the route and also the current uri, the problem is getting the theme to switch based on a taxonomy tag. I am not sure how to get the taxonomy tags for the current entity from within the theme negotiator. I would like to be able to do something similar to the following.

public function determineActiveTheme(routeMatchInterface $route_match) {
  // Get the current taxonomy tags.
  if (tag_exists) {
    return 'candy_theme';

How can I achieve this?

Your Answer

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

Browse other questions tagged or ask your own question.