diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 2c8f3fd..dcf6a5d 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1338,23 +1338,12 @@ function template_preprocess_html(&$variables) { $variables['attributes']['class'][] = 'db-offline'; } - // Add a class that tells us whether the page is viewed by an authenticated - // user. - if ($variables['logged_in']) { - $variables['attributes']['class'][] = 'user-logged-in'; - } - // Add a class that tells us what path the page is located make it possible - // to theme the page depending on the current path (e.g. node, admin, user, - // etc.) as well as more specific data like path-frontpage. + // Add a variable that tells us what path the page is located make it possible + // to create class and theme the page depending on the current path (e.g. + // node, admin, user, etc.) as well as more specific data like + // path-frontpage. $path = \Drupal::request()->getPathInfo(); - - if (drupal_is_front_page()) { - $variables['attributes']['class'][] = 'path-frontpage'; - } - else { - $segment = explode('/', $path); - $variables['attributes']['class'][] = 'path-' . Html::getClass($segment[1]); - } + $variables['root_path'] = explode('/', $path)[1]; $site_config = \Drupal::config('system.site'); // Construct page title. diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig index 5ef96cd..8869ace 100644 --- a/core/modules/system/templates/html.html.twig +++ b/core/modules/system/templates/html.html.twig @@ -4,6 +4,8 @@ * Default theme implementation for the basic structure of a single Drupal page. * * Variables: + * - logged_in: A flag indicating if user is logged in + * - is_front: A flag indicating if the current page is front page * - css: A list of CSS files for the current page. * - head: Markup for the HEAD element (including meta tags, keyword tags, and * so on). @@ -26,6 +28,12 @@ * @ingroup themeable */ #} +{% + set body_classes = [ + logged_in ? 'user-logged-in', + not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class + ] +%} @@ -34,7 +42,7 @@ {{ styles }} {{ scripts }} - +