July 2017
Intermediate to advanced
456 pages
11h 32m
English
Another method to attach a library to an individual page depends on creating a *.theme file, which allows us to use preprocess functions to manipulate page variables. We will focus a lot more on creating a *.theme file a little later, but it's important to note that we could attach the same Slick Carousel to our homepage without globally calling it using a preprocess function:
function example_preprocess_page(&$variables) {
if ($variables['is_front']) {
$variables['#attached']['library'][] = 'example/slick';
}
}
Here, we are checking to see whether we are on the homepage of our website, and attach the Slick library using the #attached library array. Again, this may seem a little bit advanced ...
Read now
Unlock full access