gpt4 book ai didi

php - Symfony:扩展原始 AppBundle 模板文件

转载 作者:可可西里 更新时间:2023-11-01 01:13:46 25 4
gpt4 key购买 nike

我在这个结构中有一个包 Acme/Bundle/BlogBu​​ndle:

app/...
app/Resources/views/base.html.twig
bin/...
Acme/Bundle/BlogBundle/Resources/views/Default/blog.html.twig
src/...
src/AppBundle/...

blog.html.twig 中,我想扩展 base.html.twig 并自动生成 AppBundle

这是我最好的猜测:

{% extends '@AppBundle/base.html.twig' %}

{% block body %}
test
{% endblock body %}

我尝试了一些其他语法,但似乎都不起作用。那么,如何将模板文件与 ov AppBundle 文件夹相互引用?

文档(对我没有帮助):http://symfony.com/doc/current/templating/namespaced_paths.html

最佳答案

TwigBundle安装在您的应用程序中(默认情况下在 SE 中)和 AppBundle ,您自动注册了这些 Twig 的路径(按此顺序):

# config.yml
twig:
paths:
# behind the scenes!!
src/AppBundle/Resources/views: App # without Bundle suffix (convention)
app/Resources/views: ~ # %kernel.root_dir%/Resources/views

意思是App命名空间(@App 作为 Twig 的约定)用于引用位于 src/AppBundle/Resources/views 中的任何模板。独家:

'(@App === src/AppBundle/Resources/views)/base.html.twig'

对于 ~符号(在 PHP 中表示 null) app/Resources/views当没有引用命名空间时使用路径来加载一些模板:

'(null === app/Resources/views/)base.html.twig'

因此 {% extends 'base.html.twig' %}如果它存在app/Resources/views中,则需要(在您的情况下)目录。

关于php - Symfony:扩展原始 AppBundle 模板文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45639038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com