Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
Allows developers to create Plugins to preprocess templates instead of hook functions.
Preprocessor Plugins grants developers the ability to create Plugins to house preprocessing logic for templates. They are a replacement and alternative to hook_preprocess_HOOK() functions.
Take this traditional hook function as an example. You would normally put this in a .theme file to add the foo variable to the node.html.twig template.
Allows developers to create dedicated files to preprocess templates instead of hook functions.
Preprocessor Files grants developers the ability to create dedicated files to house preprocessing logic for templates. They are a replacement and alternative to hook_preprocess_HOOK() functions.
Just like Drupal 7, you can affect the output of certain HTML via preprocess functions. For example, if you wanted to add a class to a menu and preferred to do this at the PHP level, you can. This is a good way to alter theme-specific markup. If you want to add or edit theme-independent markup, you should create a custom module instead.