Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Release: Opensolr Search 4.5.0 Minor update available for module opensolr_search (4.5.0). Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Usage Milestone: Simplify Module simplify crossed 10,000 active installs. Usage Milestone: Views Reference Filter Module entityreference_filter crossed 10,000 active installs. Usage Milestone: Dropdown Language Module dropdown_language crossed 10,000 active installs. Usage Milestone: Paragraphs Browser Module paragraphs_browser crossed 10,000 active installs. Usage Milestone: OpenAPI Module openapi crossed 10,000 active installs. Usage Milestone: Decoupled Router Module decoupled_router crossed 10,000 active installs. Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Twig casings

27 sites Security covered Drupal 10–11 Twig ecosystem
View on drupal.org

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.

Depends on

Dependencies of the latest stable release

  • system Drupal core >=10.0

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
7
Tracked since
Oct 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 7
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
1.0.5 Stable 10–11 Mar 11, 2025
1.0.4 Stable 10–11 Feb 21, 2025
1.0.x-dev Dev 10–11 Feb 21, 2025
1.0.3 Stable 10–11 Nov 8, 2024
1.0.2 Stable 10–11 Nov 6, 2024
1.0.1 Stable 10–11 Oct 31, 2024
1.0.0 Stable 10–11 Oct 31, 2024