July 2017
Intermediate to advanced
456 pages
11h 32m
English
The main role of preprocessor functions is to prepare variables to be used within our Twig templates using template_preprocess functions. These functions reference the theme and template we want to intercept. We can write an example of intercepting the html.html.twig template variables used within our Twig theme as follows:
First we need to create a new file called twiggy.theme.
Within our new file, add the following code:
<?php /** * Implements hook_preprocess_html(). */ function twiggy_preprocess_html(&$variables) { // add to classes $variables['attributes']['class'][] = 'twig'; }
Remember to save the file and clear Drupal's cache since we introduced a new file. If we now refresh our home page and inspect the ...
Read now
Unlock full access