Skip to content

Some Symfony templates are not respecting the "Symfony twig naming standard" #54051

Closed
@VincentLanglet

Description

@VincentLanglet

Symfony version(s) affected

all

Description

When looking at Symfony standard about template naming
(https://symfony.com/doc/current/templates.html#template-naming or https://symfony.com/doc/current/best_practices.html#use-snake-case-for-template-names-and-variables)
it's said:

Use snake case for filenames and directories (e.g. blog_posts.html.twig, admin/default_theme/blog/index.html.twig, etc.);

Now, If we look at the UnicodeString::snake() in order to knows what a valid snake case is:
https://github.com/symfony/string/blob/7.0/Tests/AbstractAsciiTestCase.php#L1063-L1077
it seems that foo_2 is not a valid snake case and should be foo2.

But, when looking at symfony code
https://github.com/symfony/symfony/tree/7.1/src/Symfony/Bridge/Twig/Resources/views/Form
all the templates with number are in the format foo_2 instead of foo2
and therefore are not respecting the own Symfony templates naming standard.

How to reproduce

Irrelevant

Possible Solution

I see four solutions:

  1. Updating the naming standard to explain the "snake_case" strategy prefix all numbers a with an underscore
    => Certainly the simplest but less satisfying solution because it kinda introduce a new naming strategy witch is not even supported by Symfony/string.

  2. Changing the snake method strategy
    => Seems this is a BC break, this seem impossible

  3. Allow passing a new parameters to snake method/introduce a new method related to this snake_case_numeric strategy
    => Since [String] Introduce underscore() method #34781 was closed, not sure it will be preferred now (@simPod & @nicolas-grekas)

  4. Renaming the templates with numbers in a BC way.
    => Might be the best solution, it just need a little work to avoid BC break.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions