There are many situations in which you need to know the theme hook, or base name, of a template file. This name is used for determining things like which preprocess function affects a template, and which template files are used for theming components.
In this article, we need understand:
- How to figure out the hook name for any template
Determine the hook name of a template
With the hook name, you can locate its base template file.
First, if you already know the filename of the template, you can infer the hook name from that.
The typical pattern for naming template files is {hook}--{optional context}.html.twig
You can ignore the
.html.twig
suffix. Which results in{hook}--{optional context}
If the file name doesn't contain a--{optional context}
part, then after removing.html.twig
you're left with the hook name.
Locate hook names in debugging output
Enable theme debugging
Open a page in your browser
View source
Example: