Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). Varbase Media Header 9.2.1 Minor update available for module varbase_media_header (9.2.1). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides Twig filters to easily transform strings into various common casing formats like camelCase, kebab-case, and snake_case. It's useful for theme development and frontend coding, helping you quickly format strings for class names and other conventions directly within your Twig templates.

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
1 year ago
Releases (12 mo)
0 ▼ from 3
Maintenance
Dormant

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