Inconsistent behavior when template filenames differ only in hyphen vs. underscore

Created on 27 February 2025, 9 days ago

Problem/Motivation

I was working with a theme that contained these template files:

  • THEME/templates/view/views-view-unformatted--research_story_list--block_card.html.twig
  • THEME/templates/view/views-view-unformatted--research-story-list--block-card.html.twig

The names differ only in their use of hyphen vs. underscore. One site used one file while another site used the other. I was trying to debug why the site, running the same code, displayed things differently. This should not happen.

Proposed resolution

Sort the template candidate filenames before replacing hyphen with underscore so that behaviour is consistent. See comments in theme_get_suggestions().

Remaining tasks

Implement.

User interface changes

None.

Introduced terminology

None.

API changes

None except that behavior will be consistent.

Data model changes

None.

Release notes snippet

🐛 Bug report
Status

Active

Version

10.4

Component

theme system

Created by

🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024