Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Twig][Config] Namespaces don't work for directories with dashes #5998

@kachkaev

Description

@kachkaev

Because dashes are being replaced with underscores in yaml config keys, it is sometimes impossible to define a new twig namespace, for example

twig:
    #...
    paths:
        /a-directory-with-dashes: myfirstnamespace
        %kernel.root_dir%/../another-directory-with-dashes: mysecondnamespace

causes an exception

[Twig_Error_Loader]                     
  The "/a_directory_with_dashes" directory does not exist.  

The same exception will fire for the second row if the first one gets removed despite that %kernel.root_dir% successfully gets replaced with real value.

Thus, the directories containing dashes can only be declared as parts of the default __main__ namespace like this:

twig:
    #...
    paths: [/a-directory-with-dashes, %kernel.root_dir%/../another-directory-with-dashes]

so the situation is definitely a bug.

A solution could be found in swapping keys and values in the config or in making the structure of paths more complicated, e.g.:

twig:
    #...
    paths:
        - {path:  /a-directory-with-dashes, namespace: myfirstnamespace}
        - {path: %kernel.root_dir%/../another-directory-with-dashes, namespace: mysecondnamespace}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions