Get the current Drupal theme?

In the context of the module, how can you determine which theme is loaded for the current user?

drupal_get_path
path_to_theme

None of them are good, because they seem to work only in template.php themes.

+3
source share
2 answers

If users are allowed to choose a theme for themselves, the selected theme is stored in $user->theme, where $useris the user object. The global variable $custom_themecontains the name of the currently installed theme, if a custom theme is defined in the module.

The following snippet is saved in the $current_themename of the current topic:

global $custom_theme, $theme, $user;

if (!empty($user->theme)) {
  $current_theme = $user->theme;
}
elseif (!empty($custom_theme)) {
  $current_theme = $custom_theme;
}
else {
  $current_theme = $theme ? $theme : variable_get('theme_default', 'garland');
}
+3
source

path_to_theme , Drupal, . , path_to_theme , , Drupal , $theme_path, , .

+1

Source: https://habr.com/ru/post/1755323/


All Articles