Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Drupal 8 Theming Foundations: Using Stable vs. Classy as a Base Theme

Parent Feed: 

For themers, there are lots of exciting new features in Drupal 8: the Twig tempting system, libraries for loading assets, and the replacement of theme functions with templates.

There are also some new core themes that come with Drupal 8. Open up the core/themes folder and you’ll see the list:

  • Bartik (our trusty default theme)
  • Classy (new!)
  • Seven (still the admin theme for D8)
  • Stable (what’s this?)
  • Stark (basically the same as in D7)

The interesting two that you’ll notice are Classy and Stable. These don’t show up on our ‘Appearance’ page like the other themes (this is because they are set to be ‘hidden’ in their .info.yml file). Instead, they’re meant to be used as base themes when you build a custom theme.

In fact the ‘stable’ theme is the de facto base theme for Drupal 8. Even if you don’t tell Drupal you want to use it as the base theme, it will be used automatically.

The ‘classy’ theme is the base theme to use if you want to start with a version of Drupal core with more classes. For example, if you want to have body classes available that indicate whether the current user is logged in, whether the current page is the front page, and what the current language of the site is, then classy is the theme for you. If your theme name is mytheme, you’d add the following in mytheme.info.yml:

base theme: classy

If you want to choose to insert classes only when you need them, a more clean approach, then you can omit mentioning any base theme. You’ll be extending the stable theme by default. The templates in the stable theme are identical to those in Drupal core, but all conveniently located in a folder that themers can find.

If you want to use the stable theme as a base theme, you might need to add additional classes to your templates. For example, if you want to add a frontpage class to the body tag, you can do the following:

<body {{ attributes.addClass('frontpage') }}>

Find more about using and manipulating attributes in Drupal 8 templates in the Drupal.org Theming Guide.

Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web