[英]Symfony: Extending the original AppBundle template files
我在这个结构中有一个Acme/Bundle/BlogBundle
:
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
文件夹中引用模板文件?
Docs(对我没有帮助): 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
as 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
目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.