diff --git a/core/includes/theme.inc b/core/includes/theme.inc index dcf6a5d..73a935d 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -1338,10 +1338,9 @@ function template_preprocess_html(&$variables) { $variables['attributes']['class'][] = 'db-offline'; } - // 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. + // Add a variable for the root path. This can be used to create a class and + // theme the page depending on the current path (e.g. node, admin, user) as + // well as more specific data like path-frontpage. $path = \Drupal::request()->getPathInfo(); $variables['root_path'] = explode('/', $path)[1]; diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 918e738..3376b91 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -521,7 +521,7 @@ function node_is_page(NodeInterface $node) { function node_preprocess_html(&$variables) { // If on an individual node page, add the node type to body classes. if (($node = \Drupal::routeMatch()->getParameter('node')) && $node instanceof NodeInterface) { - $variables['attributes']['class'][] = Html::getClass('node--type-' . $node->getType()); + $variables['node_type'] = $node->getType(); } } diff --git a/core/modules/system/templates/html.html.twig b/core/modules/system/templates/html.html.twig index 8869ace..888cf2d 100644 --- a/core/modules/system/templates/html.html.twig +++ b/core/modules/system/templates/html.html.twig @@ -4,8 +4,9 @@ * 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 + * - logged_in: A flag indicating if user is logged in. + * - root_path: The root path of the current page (e.g., node, admin, user). + * - node_type: The content type for the current node, if the page is a node. * - css: A list of CSS files for the current page. * - head: Markup for the HEAD element (including meta tags, keyword tags, and * so on). @@ -31,7 +32,8 @@ {% set body_classes = [ logged_in ? 'user-logged-in', - not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class + not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class, + node_type ? 'node--type-' ~ node_type|clean_class, ] %}