Twigsuggest enhances Drupal's theming capabilities by providing numerous additional template suggestions for various elements like blocks, nodes, users, forms, and taxonomy terms. It helps theme developers create more specific and targeted Twig templates for different content types and configurations, especially useful for platforms allowing custom theming without code.
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 (and node ID)
- Page templates per node type (and node ID)
- 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 #2752443: Incorrect order and duplicate theme hook 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.
The legacy 8.x-1.x branch (Drupal 8–10) predates the module's move to semantic versioning and was superseded by 2.0.x (Drupal 8–11); 2.0.x now receives compatibility fixes only, while new development — including the ordering fixes and node-ID suggestions above — happens on 3.0.x (Drupal 10–12). New sites should start on 3.x; see the README for notes on upgrading from 2.x.
Other modules already cover some template suggestion use cases quite well. In those cases, use the other modules:
- For block templates per block type, use Block Type Templates.
- For form elements per element type and form ID, use Themable forms.
- For node templates selected by content editors on a per-node basis, see Template Whisperer.
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.
Ask your assistant about Twig Template Suggester
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
1 tracked project depends on this one
- Drutopia 32 sites
Activity
Release Timeline
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 3.0.0-alpha1 | Pre-release | 10–11 | Sep 10, 2026 | ||
| 2.0.0-rc4 | Pre-release | 8–11 | Dec 19, 2024 | ||
| 2.0.0-rc3 | Pre-release | 8–11 | Sep 17, 2024 | ||
| 2.0.x-dev | Dev | 8–11 | Sep 17, 2024 | ||
| 8.x-1.0-rc2 | Pre-release | 8–10 | Apr 24, 2023 | ||
| 2.0.0-rc2 | Pre-release | 8–10 | Apr 24, 2023 | ||
| 8.x-1.0-rc1 | Pre-release | 8–10 | Jan 31, 2023 |