Theme Negotiators - Switch theme dynamically | Drupal 8

Theme Negotiators - Switch theme dynamically

Submitted by editor on Sun, 10/30/2016 - 17:02

How to Switch theme dynamically on drupal 8 , using theme negotiators ?

Create a custom module (here : example)

For active themes by route you first have to define a service in your $ file:



    class: Drupal\example\Theme\ExampleNegotiator
      - { name: theme_negotiator, priority: 0 }

and then use that new defined service class:
Create a class ExampleNegotiator on example/src/Theme With:

namespace Drupal\example\Theme;

use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Drupal\Core\Routing\RouteMatchInterface;

class ExampleNegotiator implements ThemeNegotiatorInterface {
   * {@inheritdoc}
  public function applies(RouteMatchInterface $route_match) {
    // Use this theme on a certain route.
    return $route_match->getRouteName() == 'example_route_name';

   * {@inheritdoc}
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    // Here you return the actual theme name.
    return 'stark';//The theme name



sankarprakash (not verified)

Thu, 04/05/2018 - 13:39

I followed the below article here you can find how to switch your theme

Drupal 8 Switching Theme Programmatically -

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.