Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Twig Toolkit

Security covered Under active development 13 sites

Part of the Twig ecosystem · 43 projects

Twig Toolkit for Drupal provides convenient Twig helpers for creating HTML classes, attributes, and inline styles within Drupal templates. It also includes an `html_element` tag that works seamlessly with Drupal's Attribute objects, making it useful for component-driven theming and design systems.

Drupal integration for studiometa/twig-toolkit: Twig helpers for HTML classes, attributes, and inline styles, plus a Drupal-aware html_element tag that works with core Attribute objects.

Machine name: twig_toolkit. No configuration UI - enabling the module registers the Twig extension.

Features

  • Twig extension - Studio Meta functions and filters in Drupal Twig.
  • html_element tag - accepts core Attribute (via toArray()), arrays, or hashes.
  • Thin layer - wraps the MIT upstream library; does not reinvent the helpers.

Functions: html_classes(), html_styles(), html_attributes(), merge_html_attributes(), twig_toolkit_url().

Filter: twig_toolkit_without.

Post-Installation

  1. composer require drupal/twig_toolkit
  2. drush en twig_toolkit -y then drush cr
  3. Use the helpers in theme Twig templates.

Example - classes and attributes

{% set classes = html_classes([
  'button',
  { 'button--primary': is_primary },
]) %}
{% set attrs = {
  class: classes,
  data_component: 'Button',
} %}
<button {{ html_attributes(attrs) }}>
  {{ 'Click me'|t }}
</button>

Example - html_element with Drupal Attribute

{% set attributes = attributes.addClass(
  'block',
  'block--featured'
) %}
{% html_element 'section' with attributes %}
  {{ content }}
{% end_html_element %}

Optional with ... argument: Drupal Attribute, array, or hash.

Additional Requirements

Similar projects

Integration layer around studiometa/twig-toolkit. Prefer core Attribute alone when you only need addClass() / setAttribute().

Supporting this Module

Issue queue for bugs and feature requests.

Community Documentation

Full API and more examples: README on git.drupalcode.org.

Drupal 10–11 PHP >=8.3

Ask your assistant about Twig Toolkit

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

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
5
Tracked since
Mar 2026
Latest release
1 month ago
Releases (12 mo)
5 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.0.4 Stable 10–11 PHP >=8.3 Sep 22, 2026
1.0.3 Stable 10–11 Mar 20, 2026
1.0.2 Stable 10–11 Mar 20, 2026
1.0.1 Stable 10–11 Mar 20, 2026
1.0.x-dev Dev 10–11 Mar 10, 2026