Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By Victor Safronov on
How can I properly set a class for body tag for the front page?
mytheme_preprocess_html() have an access to body attributes, but it doesn't know if the page is front.
And mytheme_preprocess_page() have is_front, but I can't set attributes in there.
Comments
Sandbox module available for Custom body class
Sandbox module available https://www.drupal.org/sandbox/rahulbaisanemca/2583147 Might be that will work you can also get idea from it
--
Naveen Valecha
http://valechatech.blogspot.in
Several ways
Are you using Classy as a base theme? If so then you get such classes automatically, otherwise you can add to your html.hmtl.twig template:
This will give you a "path" class, one of which will be "path-frontpage". Note this is recommended way to add classes in D8.
If you want to do this in PHP then you have to use hook_preprocess_html(), and add an attribute, e.g. do something like this:
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.