Time for action – Adding assets to your theme

In Drupal 7, CSS and JS assets were added to themes via the .info file. In Drupal 8, asset management has been split out and we have the concept of an asset library. These libraries contain the CSS and JS we would like to attach. They can be applied globally or to a specific page. Let's start by creating a global-styling asset library:

  1. In your theme's directory, create a file called recipes.libraries.yml.
  2. Copy the following into your file and save:
      version: 1.0
          css/style.css: {}


    Indentation has meaning in .yml files, so ensure that the indentation in the preceding code matches your file.

  3. We now need to attach our library to the site. This can be done in two ways. If we want ...

Get Drupal 8 Development Beginner's Guide - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.