This module provides template suggestions for everything that Drupal doesn't. So far:

  • Block templates per region
  • Block templates per bundle (for custom/content blocks)
  • Block templates per provider (and if different from provider, base plugin)
  • HTML templates per node type
  • Page templates per node type
  • User templates per highest role|uid (and view mode)
  • Field templates per view mode (and bundle)
  • Book tree templates per region
  • Form templates per form ID
  • Form templates per region
  • Form templates per region and form ID
  • Local action menu links per link route
  • Menu templates per menu name
  • Menu templates per region
  • Menu templates per region and menu name
  • Taxonomy term templates per view mode (and bundle)
  • Fix entity-specific layout templates (workaround #2881195: Duplicate template suggestions/#2831144: [policy] Bundle / field name / view mode theme suggestions can conflict)
  • Container templates per type, view, if it wraps a managed file element, and whether it has a parent or not (Drupal core provides no suggestions for container templates).

In addition, it makes the {{ base_path }} variable available to all templates.

Other modules already cover some template suggestion use cases quite well. In those cases, use the other modules:

Please make your own suggestions or requests!

This is a utility module for theme developers.

It is particularly useful for "Drupal as a Service" platforms that allow twig templates but not custom code.

To add classes to existing templates, see Class It Up.

This module also serves as an example when you want to take just one or two of these template suggestions into your own theme or module, but not all of them. See Examples project for examples of pretty much everything else.

How to use

Remember that to see Twig Template Suggester's template suggestions during development, as with all template suggestions, enable Twig debugging at Admin » Configure » Development settings (/admin/config/development/settings), and look in the page source (inspect or view source in your browser) for template name suggestions.

Supporting organizations: 
Conceived and developed, and helps maintain.
The Drutopia Platform Cooperative gives this module a reason for being, as comprehensive Twig template suggestions is crucial for Drupal as a hosted service without custom PHP allowed.

Project information

Releases