Subthemes

One point of interest in Drupal 8 is that there is a new base theme named Classy, which both Bartik and Seven reference. This means that Bartik and Seven in reality are subthemes. So why not learn from the best, in this case, Morten Birch Heide-Jørgensen, otherwise known as "Div Killer." Morten has come through, as his nickname suggests, and created one hell of a base theme.

To become a little more intimate with this new base theme, we will create a subtheme of our own called Sassy. Since the steps involved to create and install a subtheme are similar to a starter theme, we will progress a little faster through this first part.

Adding the theme folder

Begin by navigating to our themes folder and create a new folder inside named sassy.

Including a screenshot

Go ahead and copy screenshot.png from the Chapter04/start/themes/sassy folder and place it within the themes/sassy folder.

Configuring our theme

Begin by creating a new file in our themes/sassy folder named sassy.info.yml and add the following metadata to our file:

name: Sassy
type: theme
description: 'A Classy sub theme but a little more Sassy'
core: 8.x
base theme: classy

Note that we are setting the base theme configuration to classy this time. Setting this value to classy lets Drupal know that our subtheme will inherit all the configuration and files from the base theme.

We will save our changes at this time and clear the Drupal cache. Now we can take a look to see if our theme is available to install.

Installing our theme

Navigate to /admin/appearance within our browser and we should see our new theme located in the Uninstalled themes section. Go ahead and install the theme by clicking on the Install and set as default link:

Installing our theme

This time when we navigate to our homepage, we will see that our markup has changed, we are now inheriting the markup and libraries from Classy. We can verify this by using Chrome's developer tools to inspect the page. Looking at the FILE NAME SUGGESTIONS of any region, we will note that the Twig templates are coming from core/themes/classy/templates/*, as follows:

Installing our theme
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.198.81