1
votes

I did a symfony migration from version 2.7 to version 3.4

Every thing is ok except one thing. The twig files are not working the error message is :

Unable to find template "::layout.html.twig" (looked into: vendor\symfony\symfony\src\Symfony\Bridge\Twig/Resources/views/Form, vendor\knplabs\knp-menu\src\Knp\Menu/Resources/views) in abcdBundle::layout.html.twig at line 3.

The twig code is :

{% extends "::layout.html.twig" %}

I want to load the layout localised into app/Resources/views/layout.thml.twig. I have tried this code too : {% extends "layout.html.twig" %} without :: same troubles.

Location files:

app/
    Resources/
        views/
            layout.html.twig // it don't find this twig

src/
    ab/
        cdBundle/
            Ressources/
                views/
                    layout.html.twig // error into this file
2
Colon based template paths are no longer supported by default. stackoverflow.com/questions/47832977/… - Cerad
@Cerad Ok, but how to solve my issue ? I have already seen this post. But I did not understand how to make my twig work again. - R3tep
Use twig namespaces (preferred solutions) or add the twig engine to your templating config as shown at the very end of the admittedly lengthy answer. I am assuming that this all worked under your 2.7 app and there are no typos etc. - Cerad
@Cerad I have already added the templating config. All working yes before the migration. I tried this code: {% extends "@App/layout.html.twig "%} (with namespace), I have this error There are no registered paths for namespace" App ". - R3tep
For 3.4 I would expect @AppBundle/layout.html.twig. "bin/console debug:twig" will show you available namespaces. But just plain layout.html.twig really should work. And while I suspect it is just a question typo, Ressources is spelt wrong. I know it can be very confusing because there are several different directory structures supported for 3.4. - Cerad

2 Answers

1
votes

If you want to make your project more bulletproof and ready for future migrations to Symfony 4 – consider moving all your Resources away from app/ directory.

You can find more ie. in here:

http://fabien.potencier.org/symfony4-directory-structure.html

0
votes

I have updated the config.yml file to add :

twig:
    paths:
        '%kernel.project_dir%/app/Resources/views': app

This added the "Namespace" @app in the "Loader Paths" of bin/console debug:twig

Now, when I use {% extends "@app/layout.html.twig" %} its working fine.

Thank @Cerad for your help, it's very appreciated