Note: This repository contains the 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.
This module provides two Twig extensions used in the Emulsify Design System.
Twig function that inserts static classes into Pattern Lab and adds them to the Attributes object in Drupal
<h1 {{ bem('title') }}>
This creates:
<h1 class="title">
<h1 {{ bem('title', ['small', 'red']) }}>
This creates:
<h1 class="title title--small title--red">
<h1 {{ bem('title', ['small', 'red'], 'card') }}>
This creates:
<h1 class="card__title card__title--small card__title--red">
<h1 {{ bem('title', '', 'card') }}>
This creates:
<h1 class="card__title">
<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">
<h1 {{ bem('title', '', '', ['js-click']) }}>
This creates:
<h1 class="title js-click">
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>
- Node.js v12+
- Yarn Package Manager
- Commitizen for commit standardization, included in install
- Run
npm install
to install dependencies. You're done!
To facilitate automatic semantic release versioning, we utilize the Conventional Changelog standard through Commitizen. Follow these steps when commiting your work to ensure a better tomorrow.
- Stage your changes, ensuring they encompass exactly what you wish to change, no more.
- Run
yarn commit
and follow the prompts to craft the perfect commit message. - Rejoice! For now your commit message will be used to create the changelog for the next version that includes that commit.
There's a two-step process to publish a new release to the project page on Drupal.org.
- Cut a release on GitHub
- Select the generated tag for the release on Drupal.org, and set it as the "recommended" release.
- Once one or more PRs are merged into the development branch, create a "Release" PR to merge the latest from that branch into
main
. - As soon as that PR is merged, a GitHub action will kick off to cut a release based on the commit messages in that release.
- Note: This workflow will also push the new tag to drupal.org so that you can select it in the next section.
- When that is finished, you should see the new release listed on the Releases page for the repository.
- Go to the Releases tab for the Emulsify Twig project on drupal.org. (You'll need to be a maintainer to access this page.)
- Click "Add new release"
- Select the tag for the latest release and click Next
- Copy the release notes from the GitHub releases page, and reformat them according to the wysiwyg options
- Select the appropriate release type(s) (Bug fixes/New features).
- Click Save
- Back on the Releases tab, select the new release as the "Supported" and "Recommended" release. Deselect any others.
- Save, and go to the projects main page to verify that the new release is displayed in the green box so that future builds will pull it by default.