Handle hyphens in Twig template name for preview/variant

Created on 17 December 2024, 4 months ago

Problem/Motivation

According to documentation, we can use hyphens (-) in pattern ids :

id
The root of a new pattern definition (blockquote in the example above). It must contain only lowercase characters, numbers, underscores and hyphens (i.e. it should validate against [^a-z0-9_-]+).

Cf https://www.drupal.org/docs/contributed-modules/ui-patterns/define-your-...

However, when naming a pattern for example "collapsible-language", if we create a Twig file dedicated to a preview or a variant (ex : pattern-collapsible-language--preview.html.twig), this Twig file is not taken into account in the pattern library.
It's the base Twig file that is used.

It seems there is an error handling theme suggestions when using hyphens in pattern names : see attached screenshot.

If we replace the hyphen by an underscore in pattern id and file names, everything works well.

We detected this issue in 1.x, but maybe it impacts 2.x as well.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇫🇷France mh_nichts

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

Comments & Activities

  • Issue created by @mh_nichts
  • 🇫🇷France pdureau Paris

    We detected this issue in 1.x, but maybe it impacts 2.x as well.

    There are no variant specific or preview specific templates in UI Patterns 2

  • 🇫🇷France mh_nichts

    Thanks for the feedback.
    Nevertheless, I think the fix is worth being handled for v1 : to be able to use hyphens in patterns id, and preview/variant templates would be correctly used.

  • 🇫🇷France mh_nichts

    This issue affects also the preprocess naming : it works only with underscores (not possible to use hyphens).

    I guess it's more a documentation issue then : it shouldn't be allowed to use hyphens in a pattern id ?

Production build 0.71.5 2024