Form Twig Template Suggester
This module provides stable Twig template suggestions for individual form elements, allowing themes to override specific fields or buttons predictably. It generates cache-safe, form-scoped template names like `input--submit--form--contact--submit.html.twig`. This is particularly useful for site builders and themers who need to customize forms where HTML IDs might change, such as with Webform or Views.
Form Twig Template Suggester gives themes stable Twig suggestions for individual form controls (text fields, selects, buttons, and more). That means you can override one submit button or one field in a specific form without fighting Drupal’s changing HTML IDs or changing how the form submits.
It is aimed at site builders and themers who need predictable template names like input--submit--form--contact--submit.html.twig.
Features
- Automatically adds form-scoped theme suggestions for common form elements: input, select, textarea, radios, checkboxes, button, form_element, and form_element_label.
- Uses cache-safe, namespaced render-array metadata only (
#twigsuggest_form_*). It does not change core#nameor#form_idon form children, so Form API and AJAX behaviour stay intact. - Stable “source” identity per form family:
- Webform — webform machine name (for example
contact), not the long per-entity submission form id - Views exposed forms — cleaned Views form id, with consistent naming for action buttons
- Other forms — PHP form id
- Webform — webform machine name (for example
- Extensible: other modules can add tagged resolvers for custom form types.
- AJAX / FormCache friendly (including multi-step Webforms).
- Works alongside contrib twigsuggest (HTML-id style suggestions); this module focuses on form-scoped names.
When to use it: you need theme templates keyed by form + control, especially where HTML IDs change across pages or AJAX rebuilds (contact forms, search forms, multi-step forms, and similar).
Post-Installation
- Enable Form Twig Template Suggester (
twigsuggest_form). - Clear caches.
- Turn on Twig debugging (or inspect suggestions another way) and open a page with a form. Look for suggestions such as
input--submit--form--{source}--{name}.html.twigorform-element--form--{source}.html.twig. - Add matching templates in your theme, for example
input--submit--form--user_form--op.html.twigorinput--textfield--form--contact--email.html.twig.
Behaviour applies automatically to forms. If Webform or Views are installed, source IDs for those forms become more stable and theme-friendly.
Additional Requirements
- Drupal core
^11.2 - PHP 8.3+
No required contrib modules, libraries, or external APIs beyond Drupal core.
Recommended modules/libraries
- Webform — machine-name based suggestions and better support for multi-step / composite forms
- Views (in core on modern Drupal) — exposed-form source resolution
- twigsuggest — complementary ID-based suggestions; safe to use together
Similar projects
- twigsuggest — focuses on suggestions from HTML IDs / attributes. Form Twig Template Suggester instead stamps form identity in a cache-safe way and builds form-scoped suggestions without writing
data-*attributes or altering Form API#name/#form_id. - Themable Forms — classic approach of copying
#form_idonto children forform_elementsuggestions. This module uses namespaced properties only, covers more control types, and adds Webform/Views-aware source IDs.
Supporting this Module
Development is supported by Big Blue Door.
Community Documentation
- Module README and source: https://git.drupalcode.org/project/twigsuggest_form
- Issue queue: https://www.drupal.org/project/issues/twigsuggest_form
Note: This project is not (yet) covered by Drupal’s security advisory policy. Use accordingly until it opts into the security team process.
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Release Timeline
Releases
| Version | Type | Core | Notes | Release date | |
|---|---|---|---|---|---|
| 1.0.0-beta3 | Pre-release | 11 | Strip numeric delta segments from form Twig suggestions; integer render-array keys are no longer stamped as names | Jul 21, 2026 | |
| 1.0.0-beta2 | Pre-release | 11 | Beta 2: Fix TypeError when form render-array children use integer keys (Views exposed forms, multi-value widgets, numbered actions). | Jul 21, 2026 | |
| 1.0.0-beta1 | Pre-release | 11 | Initial public beta: form-scoped Twig suggestions for common form elements via cache-safe #twigsuggest_form_* stamps, with Webform and Views resolvers. Requires Drupal 11.2+. | Jul 21, 2026 | |
| 1.0.x-dev | Dev | 11 | Development snapshot of Form Twig Template Suggester (1.0.x). Use for testing; pin a tagged release for production. | Jul 21, 2026 |