Question

I have this problem, I was assigned to modify a view which is formed by two twig files (one extends from the other), with this form

layout.html.twig

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

form.twig.html

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

So, my job basically consisted in creating a in intermediate layer. But, I cannot change the files which already exists. The only allowed change is to allow the form.twig to extend from my new file, so the new scenario is:

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

Obviously this will not work!!! I cannot call block body inside ANOTHER block body on the settings file, because twig doesnt know which I am I calling (parent? descendant?) so my initial solution is

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

and everything works just fine, but Im not allowed to that since this form is used in many other places and that obviously would require to update all the files that request this form template

Any suggestions? Thanks!!

Was it helpful?

Solution

in your form.html.twig

{% extends 'yourBundle::layout.html.twig' %}
{% include "yourBundle::settings.html.twig" %}
{{block form}}
modify user settings form
{{endblock}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top