问题描述
PhpStorm version: 9.0.2
Symfony Plugin version: 0.11.109
Symfony version: 3.0.1
模板引用对于放置在app/Resources/views
下的模板文件有效,但不适用于放置在Bundle/Resources/views
下的文件.
Template referencing works fine for template files placed under app/Resources/views
but not for files placed under Bundle/Resources/views
.
这是屏幕截图.如您所见,在第一行中没有引用到app/
目录下的test.html.twig
文件的警告突出显示,但是它警告放置在捆绑软件资源下的模板.
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.
Symfony插件配置:
Symfony plugin configuration:
推荐答案
我在Symfony3
和Symfony4
上遇到了同样的问题.解决方法非常简单.
I had the same issue with Symfony3
and Symfony4
. The fix is really simple.
您要做的就是手动将app/Resources/views
(如果是Symfony4
,则为templates
)目录添加到Twig命名空间,如下所示:
All you have to do is add the app/Resources/views
(or templates
in case of Symfony4
) directory manually to Twig namespaces as follows:
这样,您还可以支持自定义Twig命名空间,因此PhpStorm也可以自动完成这些命名空间.
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
这篇关于使用Symfony插件在PhpStorm中缺少Twig模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!