3

Is there a way, on drupal 10/11, to add custom preprocess hook by bundle or view mode in a theme?

An example: the default preprocess to alter node, in theme, is

function mytheme_preprocess_node(&$vars) {}

Is there a way to create, automatically, hooks for something like mytheme_preprocess_node_VIEW_MODE, or mytheme_preprocess_node_BUNDLE, like the suggestions alter for templates?

1 Answer 1

6

Yes, you can do both. But you need two underscores:

function MYTHEME_preprocess_node__BUNDLE(&$variables) {}

function MYTHEME_preprocess_node__BUNDLE__VIEWMODE(&$variables) {}

For example:

function MYTHEME_preprocess_node__page__full(&$variables) {}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.