Cet article est aussi disponible en français
This article was written over four years ago, then updated on 15/10/2026.
This is nothing new in Drupal 8: every part of a page is rendered with a template.
There is a whole bunch of base templates:
- html.html.twig, which renders the doctype and the content of the <head> tag, and opens and closes the <body> tag
- page.html.twig, which starts where html.html.twig stops, that is to say inside the body tag
- region.html.twig for the content of a region (header, footer, content... in short, the regions defined in our theme)
- node.html.twig for the content of a node
- field.html.twig for a field defined on a content type or an entity
- block.html.twig for blocks...
Let's take as an example the node.html.twig template, which is used to display all nodes (page, article...).
These templates can be made more specific: if, for example, we want a special template for nodes of type "article", we can copy the node.html.twig file to node--article.html.twig.
There are other suggestions too:
- node--NID.html.twig, replacing NID with the id of the node in question
- node--VIEW_MODE.html.twig to use a different template when the node is displayed in "teaser" or "full" mode
- ...
You can easily find out the possible template names for an element by enabling Twig debug and looking at the HTML code of the page:

The items prefixed with * are the possible template names, and the one prefixed with x is the one actually used: these are the template suggestions. There is a set of base suggestions that is enough in most cases, but you may also want to define a more specific template.
Defining your own template suggestion
In Drupal 7 we used HOOK_preprocess_HOOK for this; in Drupal 8 a dedicated hook is available: HOOK_theme_suggestions_HOOK.
The first "HOOK" must be replaced with the name of the module implementing the hook, the second with the name of the element we want to add a suggestion for.
If we have a module called "mon_module" and we want to add a template suggestion for nodes (node), we define the following function:
function monmodule_theme_suggestions_node(array $variables) {
//...
}This function must return an array of suggestions containing the new options, for example:
function monmodule_theme_suggestions_node(array $variables) {
$suggestions = [];
$suggestions[] = 'node__montemplate';
return $suggestions;
}Note: when defining a template suggestion in code, you must replace the "--" with "__".
So:

If we want a specific html template per content type:
function monmodule_theme_suggestions_html(array $variables) {
$suggestions = [];
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') {
$bundle = \Drupal::routeMatch()->getParameter('node')->bundle();
$suggestions[] = 'html__' . bundle;
}
return $suggestions;
}
The same thing for "page":
function monmodule_theme_suggestions_page(array $variables) {
$suggestions = [];
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') {
$bundle = \Drupal::routeMatch()->getParameter('node')->bundle();
$suggestions[] = 'page__' . $bundle;
}
return $suggestions;
}And for "region":
function monmodule_theme_suggestions_region(array $variables) {
$suggestions = [];
if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') {
$bundle = \Drupal::routeMatch()->getParameter('node')->bundle();
$suggestions[] = $variables['theme_hook_original'] . '__' . $variables['elements']['#region' ] . '__' . $bundle;
}
return $suggestions;
}Note: here I used the $variables['theme_hook_original'] variable, which contains the prefix to use for each template (here "region"), while the $variables['elements']['#region'] variable contains the name of the region.
Here are the templates available this way for the "header" region when viewing content of type "article":

Of course, you can add several suggestions for the same element.
Comments (7)
Comments
Bonjour,
J'ai un soucis au niveau de l'affichage d'un template d'une de mes entités custom.
Quand je regarde ce que me renvoie le tableau du hook_theme_suggestions, j'ai bien ma bonne valeur, à savoir 'mon_entite__full' et le mode debug de twig me dit que je peux utiliser le fichier 'mon-entite--full.html.twig'.
J'ai bien créé ce fichier twig, que j'ai placé dans /themes, mais lorsque j'accède à la page, je suis renvoyé sur le contenu de l'entité dans l'administration et mon template n'est pas chargé.
Avez-vous une idée de ce que je fais de mal ?
Merci pour votre réponse,
Bonjour, le template mon-entite--full.html.twig a bien été placé dans le dossier d'un theme activé ?
S'il est à la racine du dossier thème, il ne sera pas pris en compte.
Si vous utilisez un thème de base de drupal, alors il faudra créer un theme "enfant" de celui ci, l'activer et le définir comme thème par défaut.
Oui il a été placé au bon endroit puisque j'arrive à charger le template mon-entite--teaser.twig.html.
Et bien évidemment j'ai mis mon fichier mon-entite--full.html.twig au même endroit que mon-entite--teaser.html.twig.*
Pour le coup c'est vraiment étrange, si pour un même type d'entité le template teaser fonctionnet et pas le template full... À part un problème de cache ? Je ne vois pas.
J'ai bien recréé le cache après avoir fait mes modifications.
Merci quand même pour votre aide.
bonjour
Je debute sur Drupal 8 -9 et je rencontre un souci sur la suggestion de templates pour les vues.
Une fois ma vue crée je n'ai pas de files names suggestions du coup j'ai utilisé un HOOK_theme_suggestions_hook comme indiqué et j'ai créé les fichiers cependant cela ne semble pas chargé mes fichiers.
apres avoir vidé le cache j'ai 3 files names suggestions mais aucun n'est précédé d'une croix pour indiquer celui actuellement utilisé