Chapter 4. Getting Started – Creating Themes

Drupal developers and interface engineers do not always create custom themes from scratch. Sometimes, we are asked to create starter themes that we begin any project from or subthemes that extend the functionality of a base theme. Having the knowledge of how to handle each of these situations is important, and in this chapter, we will be learning it as we cover the following:

  • First, we will create a starter theme that will walk us through managing folder and file structures, configuring a *.info.yml file, and allow us to work with a *.libraries.yml file to manage both CSS and JS assets. Our starter theme will involve multiple techniques that are common to any theme, including integrating a CSS framework such as Twitter Bootstrap.
  • Next, we will rethink over layout strategies when creating a starter theme and discuss best practices to separate layout from presentation. This will include diving deeper into the Theme layer and how we can use contributed modules such as Devel to work with variables.
  • Finally, we will create a subtheme that extends the base theme Classy. Having the ability to take advantage of a base theme's Twig templates and assets will allow us to focus on techniques to override CSS without changing the actual base themes files.

While we work through each section, we have the ability to refer back to the Chapter04 exercise files folder. Each folder contains a start folder and an end folder with files that we can use to compare our work when needed. This also includes database snapshots that allow us to start from the same point when working through various lessons. Information on how to restore database snapshots is covered in Chapter 1, Setting Up Our Development Environment.

Starter themes

Whenever we begin developing in Drupal, it is preferable to have a collection of commonly used functions and libraries that we can reuse. Being able to have a consistent starting point when creating multiple themes means that we don't have to rethink much from design to design. This concept of a starter theme makes this possible, and we will walk through the steps involved in creating one.

Before we begin, take a moment to browse the Chapter04/start folder and use the drupal8.sql file to restore our current Drupal instance. This file will add additional content and configuration needed while creating a starter theme. Once the restore is complete, our homepage should look like the following image:

Starter themes

This is a pretty bland-looking homepage with no real styling or layout. So, one thing to keep in mind when first creating a starter theme is how do we want our content to look? Do we want our starter theme to include another CSS framework or do we want to create our own from scratch?

Since this is our first starter theme, we should not be worried about recreating the wheel but instead should leverage an existing CSS framework such as Twitter Bootstrap.

..................Content has been hidden....................

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