March 2019
Intermediate to advanced
580 pages
15h 3m
English
The most common way you'll be libraries is attaching them to your render arrays. This approach implies that the library is needed for the rendering of that component so that if said component is missing from the page, the library assets are no longer included.
Here is what a render array would look like with the previous library we defined attached to it:
return [ '#theme' => 'some_theme_hook', '#some_variable' => $some_variable, '#attached' => [ 'library' => [ 'my_module/my-library', ], ],];
The #attached property is important here, and it signifies that we are essentially attaching something to the render array, which in our case happens to be a library. In Drupal 7, we could attach CSS and JS files directly, but we ...
Read now
Unlock full access