The role of the theme file in Drupal
Themes can be simple to compose, sometimes containing a single configuration file, a couple of Twig templates, and a few assets. However, there will be times when we need to intercept and override variables and data that Drupal outputs before they reach our Twig templates.
Drupal's API (https://api.drupal.org/api/drupal/8) allows us to create a *.theme
file where we can add theme functions that can hook into the API using different types of function calls:
- Preprocess: This is a set of function calls specific to different templates that allow us to manipulate variables before they are output to the page
- Hooks: This is a set of function calls to hook into the Drupal API that allows us to alter variables and override default implementations
Preprocessors and hooks
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...