Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There are no registered paths for namespace [Symfony 4.3]

I'm currently building a new bundle and, when I'm trying to include a view from that bundle into a view from the main App (directly under /templates), i've got the error :

There are no registered paths for namespace "ContentEditable" in template.html.twig at line 27.

Here is the concerned part of template.html.twig (using @ and / syntax) :

{% include '@ContentEditable/content-edition.html.twig' %}

And here is a screenshot of my files structure & the return of "bin/console debug:twig"

EDIT1

And my /config/bundles.php contains the line :

App\Paul\ContentEditableBundle\ContentEditableBundle::class => ['all' => true]

/EDIT1

Do you know what I'm doing wrong ? Is there some cache to refresh ? Why "debug:twig" doesn't even show my bundle ?

If you need further informations about the code, please let me know !

Thanks by advance !

EDIT2

Solved by @Cerad

And I just changed the namespace and the hierarchy.

Made a "Paul" repo @ the same level as src, and made the root namespace "Paul".

For people having problem with this kind of refactoring, don't forget to add something like this to your composer.json :

"autoload": {
    "psr-4": {
        "App\\": "src/",
        "Paul\\": "Paul/"
    }
},

and to add something like this to your "services.yaml" :

Paul\:
        resource: "../Paul/*"
        exclude: "../Paul/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}"

/EDIT2

like image 399
Paul ALBERT Avatar asked Mar 04 '23 07:03

Paul ALBERT


1 Answers

Rename your bundle's template directory to views (instead of templates):

src\Paul\ContentEditableBundle\Resources\views

I know it is a bit counter intuitive that the automatic twig namespace generator looks for the views directory and not templates. I know at one point there was a push to change the bundle directory layout to match the somewhat new app layout but I guess it is still a work in progress.

As an alternative, you could register your own custom twig namespace:

# config/packages/twig.yaml
twig:
    # ...
    paths:
        '%kernel.project_dir%/src/Paul/ContentEditableBundle/templates': ContentEditable        

This would perhaps future proof your directory layout.

And while off-topic I would caution against trying to mix your bundle's source code with your app source and definitely avoid using the App namespace. Lots of unexpected things might happen especially with autowire. Maybe something like:

src/
srcx/Paul/ContentEditableBundle/ContentEditableBundle.php

like image 138
Cerad Avatar answered Mar 27 '23 03:03

Cerad