O'Reilly logo

Drupal 8 Development Beginner's Guide - Second Edition by Kurt Madel, Malabya Tewari, Rakesh James, Krishna Kanth, Edward Crompton, Samuel Keen, Tassos Koutlas, Neeraj Kumar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:
    global-styling:
      version: 1.0
      css:
        theme:
          css/style.css: {}

    Note

    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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required