Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Emulsify Twig

Security covered No further development 5,302 sites

Part of the Emulsify ecosystem · 4 projects

This module provides Twig extensions for the Emulsify Design System. It includes a BEM Twig function for generating CSS classes according to the Block, Element, Modifier methodology and an `add_attributes` function to manage Drupal template attributes.

Final version of Emulsify Twig - use Emulsify Tools

Note: The 5.x version is last supported version of Emulsify Twig that will work with Drupal 10 and 11 only. Support for Drupal 9 has been dropped. The replacement for this module is Emulsify Tools where development will continue.

All work on this project is done on Github

Visit emulsify-ds/emulsify_twig to log issues and contribute.

Documentation can be found at https://docs.emulsify.info

More information at https://emulsify.info

This module provides two Twig extensions used in the Emulsify Design System.

Usage

BEM Twig Extension

Twig function that inserts static classes into Pattern Lab and adds them to the Attributes object in Drupal

Simple block name (required argument):

<h1 {{ bem('title') }}>

This creates:

<h1 class="title">

Block with modifiers (optional array allowing multiple modifiers):

<h1 {{ bem('title', ['small', 'red']) }}>

This creates:

<h1 class="title title--small title--red">

Element with modifiers and blockname (optional):

<h1 {{ bem('title', ['small', 'red'], 'card') }}>

This creates:

<h1 class="card__title card__title--small card__title--red">

Element with blockname, but no modifiers (optional):

<h1 {{ bem('title', '', 'card') }}>

This creates:

<h1 class="card__title">

Element with modifiers, blockname and extra classes (optional - in case you need non-BEM classes):

<h1 {{ bem('title', ['small', 'red'], 'card', ['js-click', 'something-else']) }}>

This creates:

<h1 class="card__title card__title--small card__title--red js-click something-else">

Element with extra classes only (optional):

<h1 {{ bem('title', '', '', ['js-click']) }}>

This creates:

<h1 class="title js-click">

Add Attributes Twig Extension

Twig function that merges with template level attributes in Drupal and prevents them from trickling down into includes.

{% set additional_attributes = {
  "class": ["foo", "bar"],
  "baz": ["foobar", "goobar"],
  "foobaz": "goobaz",
} %}

<div {{ add_attributes(additional_attributes) }}></div>

Can also be used with the BEM Function:

{% set additional_attributes = {
  "class": bem("foo", ["bar", "baz"], "foobar"),
} %}

<div {{ add_attributes(additional_attributes) }}></div>
Drupal 10–11

Ask your assistant about Emulsify Twig

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
3
Tracked since
Feb 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Release Timeline

Releases

Version Type Core PHP Release date
5.0.0 Stable 10–11 May 2, 2024
4.0.0 Stable 9–10 Feb 16, 2023
3.0.0 Stable 8–9 Feb 16, 2023