Drupal is a registered trademark of Dries Buytaert

twig_casings

16 sites Security covered
View on drupal.org

Have you ever been in Twig and thought: "I just want a filter to make my string camelCase, kebab-case, MACRO_CASE, PascalCase, snake_case, or Train-Case?"

This module allows you to pass any string with spaces, dashes, underscores, or even messy input with special characters, and it will normalise and case your string correctly.

This module is designed for Drupal 10+ and is ideal for theme developers, frontend engineers, and anyone needing quick case transformations in their templates.

Main features / functionalities:

  • ✅ Convert strings using twig filters

    Pass strings with spaces, underscores or dashes to one of the conversion filters to instantly transform your string.

  • ✅ Ideal for BEM, ABEM and other class naming conventions.

    Quickly convert strings to the casing you need for your frontend naming conventions and mix and match where needed.

  • ✅ No configuration. Just install and use!

    No complicated set up or custom code needed. Just install the module and start using the conversion filters in your twig templates!

Post-Installation

No additional configuration is required.

Once you've installed the module via composer, enable it in the UI or via drush en twig_casings and then start using the filters in twig.

The available filters are:

  • Camel case

    Usage:

    {{ 'Drupal is without-doubt the best CMS_there_is'|camel_case }}

    Output:

    drupalIsWithoutDoubtTheBestCmsThereIs

  • kebab_case

    Usage:

    {{ 'Drupal is without-doubt the best CMS_there_is'|kebab_case }}

    Output:

    drupal-is-without-doubt-the-best-cms-there-is

  • macro_case

    Usage:

    {{ 'Drupal is without-doubt the best CMS_there_is'|macro_case }}

    Output:

    DRUPAL_IS_WITHOUT_DOUBT_THE_BEST_CMS_THERE_IS

  • pascal_case

    Usage:

    {{ 'Drupal is without-doubt the best CMS_there_is'|pascal_case }}

    Output:

    DrupalIsWithoutDoubtTheBestCmsThereIs

  • snake_case

    Usage:

    {{ 'Drupal is without-doubt the best CMS_there_is'|snake_case }}

    Output:

    drupal_is_without_doubt_the_best_cms_there_is

  • train_case

    Usage:

    {{ 'Drupal is without-doubt the best CMS_there_is'|train_case }}

    Output:

    Drupal-Is-Without-Doubt-The-Best-Cms-There-Is

See the README.md on GitLab for for full usage instructions.

Additional Requirements

This module has no external dependencies beyond Drupal Core.

Similar projects

  • Twig Tweak module: provides a variety of Twig functions and filters which are Drupal specific but nothing related to string case conversion.

  • Twig Tools module: provides a variety of Twig conversion filters but nothing related to string case conversion.

Community Documentation

A YouTube walkthrough of all the functionality this module provides is coming very soon!

Supporting organization

Pivale are a globally trusted web development company who build Drupal CMS websites and software.

Activity

Total releases
3
First release
Feb 2025
Latest release
11 months ago
Release cadence
9 days
Stability
67% stable

Release Timeline

Releases

Version Type Release date
1.0.5 Stable Mar 11, 2025
1.0.4 Stable Feb 21, 2025
1.0.x-dev Dev Feb 21, 2025