Search code examples
phpstormsymfony

Missing Twig template in PhpStorm with Symfony Plugin


PhpStorm version: 9.0.2
Symfony Plugin version: 0.11.109
Symfony version: 3.0.1

Template referencing works fine for template files placed under app/Resources/views but not for files placed under Bundle/Resources/views.

Here goes screenshot. As you can see there is no warning highlight at first line that references to the test.html.twig file placed under app/ directory, but it warns on templates that are placed under bundle resources.

Code works well and bundle templates renders in browser.

enter image description here

Symfony plugin configuration:

enter image description here


Solution

  • I had the same issue with Symfony 3 / 4 / 5. The fix is really simple.

    All you have to do is add the app/Resources/views (or templates in case of Flex) directory manually to Twig namespaces as follows:

    Twig namespaces settings

    This way you can also support custom Twig namespaces, so PhpStorm can autocomplete those as well.


    If it's not working immediately, you should invalidate the cache:

    File -> Invalidate Caches / Restart