Form Twig Template Suggester
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.
- There is no configuration page, no new content types, and nothing to set under text formats.
- 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.