包括子目录中的树枝文件 [英] Including the twig file from a subdirectory

查看:24
本文介绍了包括子目录中的树枝文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题 - 当它被放置在子目录中时,我不能在另一个 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 其他视图的路径也是如此).在该文件中,我包含一个文件 Status.html.twig 放在 AppUserBundle:Dashboard:User 子目录中.但是当尝试包含它时,我收到消息找不到模板".

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 文件.

这篇关于包括子目录中的树枝文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆