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 them reaching 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 ...

Get Drupal 8: Enterprise Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.