While we will cover Twig a little later, we need to pause for a moment to explain a Twig function used with referencing a library named {{ attach_library() }}. This function allows us to add a library that may include CSS or JS that will load on that page only to any Twig template.
For example, if we wanted to add the Slick Carousel (http://kenwheeler.github.io/slick/) to our page, we may define the library within our example.libraries.yml file, as follows:
# Slick
slick:
version: VERSION
css:
theme:
vendor/slick/slick.css: {}
js:
vendor/slick/slick.min.js: {}
dependencies:
- core/jquery
We could then turn around and add the following to our Twig template:
{{ attach_library('example/slick') }}
This provides us with a nice functionality to define individual libraries for various user functions and to have those assets used wherever we choose to attach them.