Drupal is a registered trademark of Dries Buytaert
drupal 11.3.8 Update released for Drupal core (11.3.8)! drupal 11.3.7 Update released for Drupal core (11.3.7)! drupal 11.2.11 Update released for Drupal core (11.2.11)! drupal 10.6.7 Update released for Drupal core (10.6.7)! drupal 10.5.9 Update released for Drupal core (10.5.9)! cms 2.1.1 Update released for Drupal core (2.1.1)! drupal 11.3.6 Update released for Drupal core (11.3.6)! drupal 10.6.6 Update released for Drupal core (10.6.6)! cms 2.1.0 Update released for Drupal core (2.1.0)! linkit 7.0.14 Minor update available for module linkit (7.0.14). masquerade 8.x-2.2 Minor update available for module masquerade (8.x-2.2). video_embed_field 3.1.0 Minor update available for module video_embed_field (3.1.0). bootstrap 8.x-3.40 Minor update available for theme bootstrap (8.x-3.40). menu_link_attributes 8.x-1.7 Minor update available for module menu_link_attributes (8.x-1.7). editoria11y 3.0.0 Major update available for module editoria11y (3.0.0). trash 3.0.27 Minor update available for module trash (3.0.27). twig_tweak 4.0.0-alpha2 New alpha version released for module twig_tweak (4.0.0-alpha2). twig_tweak 4.0.0-alpha1 First alpha version released for module twig_tweak (4.0.0-alpha1). node_revision_delete 2.1.1 Minor update available for module node_revision_delete (2.1.1). commerce_paypal 2.1.2 Minor update available for module commerce_paypal (2.1.2).

twig_toolkit

3 sites Security covered
View on drupal.org

Twig Toolkit for Drupal integrates the studiometa/twig-toolkit library with Drupal’s Twig layer. It provides ergonomic helpers for composing HTML classes, attributes, and inline styles, plus a Drupal-compatible html_element tag that works with Drupal Attribute objects.

Features

  • Exposes Twig Toolkit’s Twig helpers in Drupal templates:
    • html_classes() for building class attributes from strings/arrays/objects.
    • html_styles() for building inline style attributes from key/value maps.
    • html_attributes() and merge_html_attributes() for rendering and
      merging attributes safely and consistently.
    • {% html_element %}...{% end_html_element %} for rendering elements with
      dynamic tags and complex attributes.
  • Drupal compatibility for attribute handling:
    • Automatically converts Drupal \Drupal\Core\Template\Attribute objects to
      arrays for use with Twig Toolkit.
  • Useful for component-driven theming, design systems, and templates that need clean, reusable
    attribute composition.

Post-Installation

After enabling the module, the functions/filters/tag are immediately available in Twig templates. There is no configuration form. Use it directly in your theme/module templates to build attributes and render elements. Clear caches after enabling (e.g. drush cr).

Additional Requirements

  • Requires the PHP library
    studiometa/twig-toolkit
    (typically installed via Composer).
  • No additional Drupal modules are required beyond Drupal core.
  • No specific recommendations. This module is most useful alongside component-based theming approaches and reusable Twig components.

Similar projects

  • Twig Tweak: offers many Drupal-specific Twig utilities, but is broader in
    scope. This module focuses on integrating the Twig Toolkit attribute/class/style helpers and
    html_element tag.
  • Drupal’s core Attribute API: provides attribute objects; this module
    complements it with ergonomic composition helpers and a convenient element-rendering tag.

Supporting this Module

If you’d like to support upstream development of the underlying library, consider following and supporting the authors of studiometa/twig-toolkit.

Community Documentation

Activity

Total releases
4
First release
Mar 2026
Latest release
1 month ago
Release cadence
3 days
Stability
75% stable

Release Timeline

Releases

Version Type Release date
1.0.3 Stable Mar 20, 2026
1.0.2 Stable Mar 20, 2026
1.0.1 Stable Mar 20, 2026
1.0.x-dev Dev Mar 10, 2026