Add Logic with THEMENAME.theme for Drupal 8, Drupal 9

Last updated July 27, 2016
Theming8.9.x/9.0.x

Every theme can contain an optional THEMENAME.theme file. This file contains additional business logic written in PHP and is primarily used for manipulation of the variables available for a template file, and suggesting alternative candidate template file names.

In this tutorial we'll learn:

  • The use-case for THEMENAME.theme files
  • Where to find them
  • When you might need to edit one