0
这有点复杂的解释。我的使用情况如下:Twig基于路径的重载
比方说,我有以下文件系统结构:
/client/name/web/dashboard.twig <- extends dashboard.twig - file might not exist
/app/name/web/dashboard.twig <- extends dashboard.twig - file might not exist
/web/dashboard.twig <- extends layout.twig - file always exists
/web/layout.twig <- the base template - file always exists
假设我跑$twig->render('dashboard.twig');
,我希望它开始与最上面dashboard.twig
,继续作为顺序去上面指定的顺序。
目前的问题是,小枝最后会在无限循环中试图每次加载第一个模板文件。 在the recipes section中,有一个例子可以避免使用路径。这不能在我的情况下工作,因为的几个问题:
- 的
/client/name/web/dashboard.twig
的开发商不应该知道/app/name/web/dashboard.twig
文件。 - 仍然无法识别
name
路径段,因此路径概念无法工作。
我能想到的唯一解决方案是以某种方式插入树枝并告诉它在加载后立即“弹出”模板文件,以消除无限循环。
API文档的这一部分似乎有用:http://twig.sensiolabs.org/api/master/Twig_Loader_Filesystem.html