Score:0

How can i add a class with 'html' tag(not with body) for specified pages (10 nodeID's)?

ye flag

How can i add a class with 'html' tag(not with body) for some specified pages (10 nodeID's) ? I tried with html preprocess, but didn't worked,

Score:0
de flag

You can override html.html.twig in your theme as html--node--[NID].html.twig, and add the class into the HTML in that template.

<html{{ html_attributes.addAttribute("my attribute") }}>
Score:0
in flag

You can add template_preprocess_html to your module and add the classes via $variables['html_attributes']['class'].

Since this is html.html.twig's preprocessor, it has no notion of what a Node is. It could also be rendering a non-node page (e.g. the user login). Some modules may add Node information to the variables, but there is no guarantee. To be safe, you'll have to check if the current route is a node and then check the IDs afterward.

function your_module_preprocess_html(&$variables) {
  if ($is_current_rout_is_a_node) {
    if ($is_this_the_right_node) {
      $variables['html_attributes']['class'][] = 'your class';
    }
  }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.