HOWTO: Adding node type class to body element in Drupal 8

Method 1: edit your html.html.twig theme template

Add this line at   <body{{ attributes.addClass(classes,:

    node_type ? 'page-node-type-' ~ node_type|clean_class

For example:

  <body{{ attributes.addClass(classes,
    not is_front ? 'with-subnav',
    sidebar_first ? 'sidebar-first',
    sidebar_second ? 'sidebar-second',
    (sidebar_first and not sidebar_second) or (sidebar_second and not sidebar_first) ? 'one-sidebar',
    (sidebar_first and sidebar_second) ? 'two-sidebars',
    (not sidebar_first and not sidebar_second) ? 'no-sidebar',
    node_type ? 'page-node-type-' ~ node_type|clean_class
  ) }}>

Method 2: Try node_type_class module

 

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.