23
votes
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

2
Sometime the cache is not correctly refreshed, moreover you must have generated your "dev" cache. Synchonrize / Invalidates sometimes correct the problem. (and/or restart) - COil

2 Answers

46
votes

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
8
votes

I just had the same problem as well, however I didn't want to follow @Andrey Rudenko's answer because I would lose all my project specific configuration. Instead I followed @COil's comment and jusnt invalidated my cache and the problem was solved.

File -> Invalidate Caches / Restart -> Invailidate and Restart