2014-04-10 90 views
1

我有這樣的問題,我被分配到修改由兩個枝杈文件(一個從另一個延伸)形成的視圖,這種形式的問題樹枝塊名稱

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}} 

,一切工作正常,但由於這種形式在其他許多地方使用,並且顯然將需要更新所有請求此表單模板

任何建議的文件,我不是不允許嗎? 謝謝!

+0

你不必延長,你必須_include_。 – moonwave99

回答

1

在form.html.twig

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