4

I am trying to do some theming for Drupal 8 and I was trying to understand what theme is being used on a given page. I remember using theme developer module in Drupal 7, and using dpm() of the page array after theme developer started having issues.

How can I achieve the same with Drupal 8?

8

In Drupal 8, you can do two things from custom code:

\Drupal::theme()->getActiveTheme();

\Drupal::theme()->getActiveTheme()->getName();

The first will return a theme object, the second will return just the theme name.

See the ThemeManager docs for more details.

You can also install Devel/WebProfiler for more information about the current page request and other variables.

0

Global theme variables got replaced by an ActiveTheme in Drupal 8.

In Drupal 7 you could access and set the current active theme via global variables like $GLOBALS['theme_key'] and $GLOBALS['theme'].

In Drupal 8 this is replaced by an ActiveTheme object available via the 'theme.manager' service:

Example code in Drupal 7:

drupal_set_message(t("Active theme name: @name", array('@name' => $GLOBALS['theme_key'])));

Code in Drupal 8:

drupal_set_message(t("Active theme name: @name", array('@name' => \Drupal::theme()->getActiveTheme()->getName())));

On top of the theme name the ActiveTheme (\Drupal\Core\Theme\ActiveTheme) object provides all runtime information needed about the active theme, like the path to the active theme:

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.