This project is not covered by Drupal’s security advisory policy.

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 #name or #form_id on 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
  • 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

  1. Enable Form Twig Template Suggester (twigsuggest_form).
  2. Clear caches.
  3. 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.twig or form-element--form--{source}.html.twig.
  4. Add matching templates in your theme, for example input--submit--form--user_form--op.html.twig or input--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.

  • 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_id onto children for form_element suggestions. 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

Note: This project is not (yet) covered by Drupal’s security advisory policy. Use accordingly until it opts into the security team process.

Supporting organizations: 

Project information

Releases