包含子目录中的 twig 文件 [英] Including the twig file from a subdirectory
问题描述
我遇到了一个问题 - 当一个 twig 文件被放置在子目录中时,我无法将其包含在另一个 twig 文件中.示例:
I've got a problem - I can't include a twig file in another twig file when it's placed in the subdirectory. Example:
我有一个文件 AppUserBundle:Dashboard:index.html.twig
(symfony 路径是 src/App/UserBundle/Resorcues/views/Dashboard/index.html.twig
等其他视图的路径).在那个文件中,我包含了一个位于 AppUserBundle:Dashboard:User
子目录中的文件 Status.html.twig
.但是在尝试包含它时,我收到消息找不到模板".
I've got a file AppUserBundle:Dashboard:index.html.twig
(symfony path is src/App/UserBundle/Resorcues/views/Dashboard/index.html.twig
and so are the other views' paths).
In that file I've got include for a file Status.html.twig
placed in AppUserBundle:Dashboard:User
subdirectory. But when trying to include it I'm getting message 'can't find template'.
{% include 'AppUserBundle:Dashboard:User:Status.html.twig' %}
当我将 Status.html.twig 文件移动到 AppUserBundle:Dashboard
目录并包含它时,一切正常.我可以以某种方式访问任何这样的文件吗?
When I move the Status.html.twig file to AppUserBundle:Dashboard
directory and include it everything works just fine. Can I somehow get to any file like that?
AppUserBundle:Dashboard:Subdir:file
推荐答案
AcmeDemoBundle:Welcome
只是一个逻辑控制器名称,:
并不意味着 /代码>.这个逻辑名称指的是
@AcmeDemoBundle/Resources/views/Welcome
目录,其中 @AcmeDemoBundle
是一个逻辑包名称,类似于 src/Acme/DemoBundle代码>.
AcmeDemoBundle:Welcome
is just a logical controller name, the :
doesn't mean a /
. This logical name refers to the @AcmeDemoBundle/Resources/views/Welcome
directory where @AcmeDemoBundle
is a logical bundle name which become something like src/Acme/DemoBundle
.
如果您想在名称中添加另一个目录,只需像往常一样将其放在逻辑名称之后:
If you want to add another directory to the name, just place it after the logical name as you normally do:
AcmeDemoBundle:Welcome:User/index.html.twig
这是指 src/Acme/DemoBundle/Resources/views/Welcome/User/index.html.twig
文件.
这篇关于包含子目录中的 twig 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!