[英]Specification of multiple Twig paths in a yaml getting ignored
My twig.yaml file in a nearly fresh Bolt CMS (Symfony 5.4) project looks like this...我在一个几乎全新的 Bolt CMS(Symfony 5.4)项目中的 twig.yaml 文件看起来像这样......
twig:
...
paths:
'%kernel.project_dir%/public/theme/%bolt.theme%': 'theme'
'%kernel.project_dir%/vendor/bolt/core/templates/': 'bolt'
'%kernel.project_dir%/src/templates': 'templates'
'%kernel.project_dir%/vendor/bolt/core/templates': ''
... and my controller looks like this when it "works"... ...而我的 controller 在“工作”时看起来像这样...
<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
#[Route('/default', name: 'app_default')]
public function index(): Response
{
return $this->render('default/index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
}
... but when I change default/index.html.twig
in my controller to say myplace/index.html.twig
instead, I find that my custom template does not load. ... but when I change
default/index.html.twig
in my controller to say myplace/index.html.twig
instead, I find that my custom template does not load. Instead, I get this...相反,我得到这个......
Unable to find template "myplace/index.html.twig" (looked into: /path/to/project/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views, /path/to/project/vendor/bolt/core/templates, /path/to/project/vendor/symfony/twig-bridge/Resources/views/Form).
找不到模板“myplace/index.html.twig”(查看:/path/to/project/vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views,/path/to/project/vendor /bolt/core/templates,/path/to/project/vendor/symfony/twig-bridge/Resources/views/Form)。
Now here's the interesting part: When I put the following into twig.yaml...现在这是有趣的部分:当我将以下内容放入 twig.yaml...
twig:
...
paths:
'%kernel.project_dir%/public/theme/%bolt.theme%': 'theme'
'%kernel.project_dir%/vendor/bolt/core/templates/': 'bolt'
'%kernel.project_dir%/src/templates': ''
'%kernel.project_dir%/vendor/bolt/core/templates': 'templates'
... my new template in src/templates/myplace
starts showing up in the browser. ...我在
src/templates/myplace
中的新模板开始显示在浏览器中。 At that point, of course, Bolt's default Twig templates stop working, meaning I can't use the CMS.那时,当然,Bolt 的默认 Twig 模板停止工作,这意味着我无法使用 CMS。
How can I make both sets of templates findable by Symfony?如何让 Symfony 找到这两组模板?
EDIT: I thought maybe templates
was some sort of reserved word, so I tried changing the name assigned to src/templates
in twig.yaml
from templates
to bob
.编辑:我认为
templates
可能是某种保留字,所以我尝试将twig.yaml
中分配给src/templates
的名称从templates
更改为bob
。 That did not do the trick, unfortunately.不幸的是,这并没有奏效。 Obviously,
myplace
exists, because the template is rendered correctly when I remove the key.显然,
myplace
是存在的,因为当我移除密钥时,模板会正确呈现。 It's just that having a key in there somehow causes the template resolution to fail.只是在那里有一个键会导致模板解析失败。
Well... that was embarrassingly simple.嗯……这太简单了。 I just had to remove the values assigned to both of the locations via my
twig.yaml
file.我只需要通过我的
twig.yaml
文件删除分配给这两个位置的值。 So that yaml now looks like this:所以 yaml 现在看起来像这样:
twig:
...
paths:
'%kernel.project_dir%/public/theme/%bolt.theme%': 'theme'
'%kernel.project_dir%/vendor/bolt/core/templates/': 'bolt'
'%kernel.project_dir%/src/templates': ''
'%kernel.project_dir%/vendor/bolt/core/templates': 'templates'
I'm honestly not sure why bolt is assigning values ('theme' and 'bolt') to these path keys in the first place, since it seems to cause things to break when I do it elsewhere in the same yaml file.老实说,我不确定为什么bolt首先为这些路径键分配值('theme'和'bolt'),因为当我在同一个yaml文件的其他地方执行此操作时,它似乎会导致事情中断。 Maybe a bolt cms expert can chime in on that.
也许螺栓 cms 专家可以插话。 For now, I'm not touching what bolt has preconfigured, out of FUD.
目前,我还没有触及 FUD 中预先配置的螺栓。 I'll just leave those values there in case removing them breaks something, praying feverishly to Winnie the Pooh that all things seen and unseen will be well forevermore.
我会把这些值留在那里,以防删除它们会破坏某些东西,并狂热地向小熊维尼祈祷,所有可见和不可见的东西都会永远好起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.