Twig Template Naming Conventions
Drupal loads templates based on specific naming conventions. This allows you to override templates by adding them to your theme and assigning specific names.
After adding a template, you must rebuild the cache so that Drupal can detect your new template.
You can debug Twig templates to find out which templates are used to render markup for any given element. More on debugging Twig here.
This page lists the conventions used for the base HTML structure, page, regions, blocks, nodes, fields, and other core components. (It’s helpful to know you can create your own template name suggestions using hook_theme_suggestions_HOOK_alter.)
HTML (<head> template)
The HTML template provides markup for the basic structure of an HTML page, including the <head>, <title>, and <body> tags.
Base template: html.html.twig (base location: core/modules/system/templates/html.html.twig)
Here are some examples of how you can override the base template:
- html--[internalviewpath].html.twig
- html--node--[nodeid].html.twig
- html.html.twig
See html.html.twig API documentation.
Page template
Template: page--[front|internal/path].html.twig
Base template: page.html.twig (base location: core/modules/system/templates/page.html.twig)
Suggestions are numerous. The front page takes precedence. The rest is based on the internal path of the current page. The front page can be selected under Administration > Configuration > System > Site information. (http://example.com/admin/config/system/site-information). The front page template is page--front.html.twig.
Do not confuse the internal path with path aliases, which are ignored.
Template suggestions are listed in order of specificity based on internal paths. One suggestion is made for each element of the current path, although numeric elements are not carried into subsequent suggestions. For example, “http://www.example.com/node/1/edit” results in:
- page--node--edit.html.twig
- page--node--1.html.twig
- page--node.html.twig
- page.html.twig
See page.html.twig API documentation. Also see maintenance page template below.
Drupal’s online documentation is © 2000-2020 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.