Back to top

Where to place Drupal Twig template files

Besides the usual advice to keep the templates in a special templates folder in your (sub)theme it is necessary to know which theme the template should be added to in the first place.

Default vs. Admin theme

It may be an unexpected discovery that there are usually two different themes being used on a Drupal website: the default one applied to content, the one visitors usually see, and the additional “admin” one applied to “back-end” configuration pages (the ones with path usually starting with /admin/).

Most of the time the theme you'll want to override will be the one styling the content side of things.

But there is also a part of the site that is ambiguous about whether it falls under the “front-” or “back-end”, and that part is the content Edit and Create pages.

Drupal usually has two active themes

Create/Edit content forms

There is a setting under Appearance > Administration theme (/admin/appearance) that allows you to use choose whether the admin theme should be used for editing content instead of the default theme. When adding a template for content-editing pages it's important to double-check which theme is chosen there to know which theme to add the template to.

Drupal Appearance Administration Theme Content Editing

As always, don't modify the contributed themes. Instead, add a subtheme that extends a contributed theme and add the template to the subtheme. Then adjust the Appearance settings to use the subtheme.

More complex decisions about which theme should be used on which pages can be accomplished with the help of the Switch Page Theme module or you can create your custom solution: Dynamic theme switching in Drupal 8.

Would you like me to help you with this? Or with any other Drupal problem? Contact me and I'll summon all my skills and Drupal might to solve it for you.
What did you think of this article?