Twig

How to auto-add body classes in Drupal 8

Submitted by Dan Grant on Sun, 03/26/2017 - 15:37

When creating the custom theme for this site, I decided to use Stable as the base them instead of using Zen (my preferred theme in Drupal 7 the past couple years), Bootstrap, etc.

Stable doesn't give many classes by default, unlike the Classy base theme.  In order to auto-add simple classes to different pages (so as to be able to easily target them with CSS), do two things:

1 - Copy the "html.html.twig" file from "core/themes/stable/templates/layout" into your custom theme's template directory (mine is at "themes/custom/xq42/templates/"

Subscribe to Twig