Now that we know more about render arrays, how they are structured, and the pipeline they go through, we can talk a bit about asset management from a module development perspective. Because even though it is usually a theme responsibility, module developers often have to add and use CSS and JS files to their modules, and it all happens in render arrays.
Working with CSS and JS files has become standardized in Drupal 8 compared to its previous version where we had more than one way to do things. Libraries are now key, so let's see how they work by going through some examples of making use of some CSS or JS files.
There are three steps to adding assets to your page:
- Creating your CSS/JS file
- Creating a library that includes them
- Attaching that library to a render array