Use underscores instead of hyphens in template filenames

Created on 7 November 2013, about 11 years ago
Updated 3 May 2024, 8 months ago

Problem/Motivation

Template suggestions use underscores but template files currently use hyphens. Now that we are using templates by default for themeable output, this is a little bit of mental gymnastics (phrase c/o @joelpittet) that seems unnecessary.

Originally this issue proposed that we have theme suggestions defined with hyphens but then that doesn't work too well for specific prepare/preprocess functions since they would need to be converted to underscores anyway. hook_theme_prepare_node--my_content_type() wouldn't fly.

Proposed resolution

Use underscores across the board. Theme functions, theme suggestions, and template filenames.

Before

node--my_content_type.html.twig

After

node__my_content_type.html.twig

Relevant code from drupal_find_theme_templates():

    // Transform - in filenames to _ to match function naming scheme
    // for the purposes of searching.
    $hook = strtr($template, '-', '_');

Remaining tasks

  • Discuss repercussions
  • Patch?

User interface changes

n/a

API changes

Theme suggestions would not be converted to hyphens for template files, so template files will use underscores by default.

📌 Task
Status

Closed: outdated

Version

11.0 🔥

Component
Theme 

Last updated 5 days ago

Created by

🇨🇦Canada star-szr

Live updates comments and jobs are added and updated live.
  • API change

    Changes an existing API or subsystem. Not backportable to earlier major versions, unless absolutely required to fix a critical bug.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States bnjmnm Ann Arbor, MI

    This was a nice idea when the issue was filed roughly two years before the release of Drupal 8. Now that Drupal 8+ has existed for over 8 years, such a change could be quite disruptive. While it's true the renaming would result in a small DX improvement, I'm not sure if at this point in Drupal's lifecycle it is enough of an improvement to justify forcing sites to rename, making existing documentation inaccurate, and potentially forcing some contrib to maintain multiple versions when they otherwise wouldn't have to.

    Based on a near-decade of no activity it seems like this isn't something in high demand so I'm changing the status and it can reopen if there's a rationale that justifies the tradeoff (and there might be and I'm not considering it!).

  • Status changed to Closed: outdated 8 months ago
  • 🇨🇦Canada star-szr

    I'd be happy with a closed status too :)

    At the time it was just an idea, and I agree it's too late.

    Thanks @bnjmnm!

Production build 0.71.5 2024