I am experimenting with Drupal 8. I've created a local sandbox site and created a custom theme and a custom front page using Twig (page--front.html.twig). I want to add some custom CSS that just targets the front page and I am used to targeting the body.page-node-x (Drupal 7). In Drupal 8 I am having issues adding a body class to this custom page. The only body classes I am seeing are toolbar-tray-open toolbar-fixed toolbar-horizontal.
2 Answers
2
votes
To add frontpage, logged-in and node type class for the body tag. Edit html.html.twig and add:
{%
set body_classes = [
logged_in ? 'logged-in',
not root_path ? 'frontpage' : 'path-' ~ root_path|clean_class,
node_type ? 'node--type-' ~ node_type|clean_class,
]
%}
<body{{ attributes.addClass(body_classes) }}>
0
votes
You have need to add these code in " html.html.twig" template which you can find in core themes " classy" in drupal 8
<?php
{%
set body_classes = [
logged_in ? 'user-logged-in',
not root_path ? 'path-frontpage' : 'path-' ~ root_path|clean_class,
node_type ? 'page-node-type-' ~ node_type|clean_class,
]
%}
?>