Add hyphens to block template suggestions

Created on 2 May 2019, almost 6 years ago
Updated 27 February 2025, about 2 months ago

Problem/Motivation

I've noticed that when one create a custom block, the twig naming template suggestion is taken from the description of the block. The problem is that spaces are removed. is it possible to replace space to hyphen? I think it's important to make the twig template more readable.

Example:

if i create a custom block with the description "home page section free software". space are removed and the twig template naming suggestion will be:
block--homepagesectionfreesoftware.html.twig

i will be mutch more readable if space are remplaced with "- ", for the twig template naming suggestion to be:
block--home-page-section-free-software.html.twig

Proposed resolution

For now i've found a work around by replacing space with underscore in the block description at the creation. Exemple: if block description "home_page_section_free_software", the template naming suggestion is:
block--home-page-section-free-software.html.twig

I'am also aware of the module "block content machine name" https://www.drupal.org/project/block_content_machine_name . But i think that feature should be in core. More than that , that module cause several naming problem that i will not expose here.

Remaining tasks

Add change record
Add release note snippet

User interface changes

Machine names are created a bit differently.

API changes

None

Data model changes

None

Release notes snippet

@todo

Feature request
Status

Needs work

Version

11.0 🔥

Component

block.module

Created by

🇧🇪Belgium OCTOGONE.dev Brussels

Live updates comments and jobs are added and updated live.
  • Needs product manager review

    It is used to alert the product manager core committer(s) that an issue represents a significant new feature, UI change, or change to the "user experience" of Drupal, and their signoff is needed. If an issue significantly affects the usability of Drupal, use Needs usability review instead (see the governance policy draft for more information).

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.

Production build 0.71.5 2024