1

Looking at the documentation for the Drupal 8 html.html.twig template file, I notice node_type is listed between the available variables for that template file.
Contrary to the other variables available to that template file, thought, node_type is not set from template_preprocess_html() nor _template_preprocess_default_variables(), which are the functions I expect to set the documented variables for that template file.

What function or method initializes node_type to the bundle of the currently viewed node for html.html.twig?

3

node_type is set in node_preprocess_html() from the Node module.

/**
 * Implements hook_preprocess_HOOK() for HTML document templates.
 */
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['node_type'] = $node->getType();
  }
}

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.