树枝块名称的问题

时间:2014-04-10 12:12:47

标签: forms symfony twig block

我有这个问题,我被分配修改一个由两个枝条文件(一个从另一个延伸)形成的视图,用这个表格

layout.html.twig

something here
{{ block body }}{{endblock}}
something here

form.twig.html

extends layout.html.twig
{{block body}}
modify user settings form
{{endblock}}

所以,我的工作基本上是创建一个中间层。但是,我无法更改已存在的文件。唯一允许的更改是允许form.twig从我的新文件扩展,因此新方案是:

layout.html.twig

something here
{{ block body }}{{endblock}}
something here

settings.html.twig

extends layout.html.twig
{{ block body }}
some specific section things here
now the form 
{{ block body }}{{endblock}}
{{endblock}}

form.html.twig

extends settings.html.twig
{{block body}}
modify user settings form
{{endblock}}

显然这不起作用!我不能在设置文件中调用块体内的块体,因为树枝不知道我在调用哪个(父?后代?)所以我的初始解决方案是

layout.html.twig

something here
{{ block body }}{{endblock}}
something here

settings.html.twig

extends layout.html.twig
{{ block body }}
some specific section things here
now the form 
{{ block form }}{{endblock}}
{{endblock}}

form.html.twig

extends settings.html.twig
{{block form}}
modify user settings form
{{endblock}}

并且一切正常,但我不允许这样,因为这个表单在许多其他地方使用,显然需要更新请求此表单模板的所有文件

有什么建议吗? 谢谢!

1 个答案:

答案 0 :(得分:1)

在你的form.html.twig

{% extends 'yourBundle::layout.html.twig' %}
{% include "yourBundle::settings.html.twig" %}
{{block form}}
modify user settings form
{{endblock}}