I found a paragraph in the documentation about using template files in a custom module. This way can be even used to override a template like I did here.

However, I am wondering if this is the correct way since I have read this answer.

After some research I noticed that we can see sometimes, depending on the case, the use of:

  • hook_theme alone
  • hook_theme with hook_theme_suggestions_HOOK_alter
  • hook_theme_registry_alter

What are the subtleties between these different ways to create or override a template?

The documentation for hook_theme, which is not clear for me, states:

The keys on the outer array are known as "theme hooks". For theme suggestions, instead of the array key being the base theme hook, the key is a theme suggestion name with the format 'base_hook_name__sub_hook_name'. For render elements, the key is the machine name of the render element. The array values are themselves arrays containing information about the theme hook and its implementation.

Does this mean: "theme suggestions" for template overriding, and "render elements" for template creation?

To summarise, is there a difference between adding a template and overriding a template, from a custom module? If so, what’s the correct way to add a template and the correct way to override a template?



Your Answer

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

Browse other questions tagged or ask your own question.