Multiple extension of layout in twig/php -


i have problem figuring out how solve following issue twig templates

i have system 2 parts wants change blocks in layout without know each other. idea of templates are

main.twig <html><body> {% block %}{% endblock %} {% block b %}{% endblock %} </body></html>  replacea.twig {% extends "main.twig" %} {% block %}hello{% endblock %}  replaceb.twig {% extends "main.twig" %} {% block b %}world{% endblock %} 

my problem not know how achieve this, places call replacea , replaceb shares "viewengine" able collect render calls , bulk them.

my first idea solve extend variable, "layout", when call render layout replaced same in templates , not "replacea.twig" in replaceb , "main.twig" in replacea.

hope understand problem.

you need use "use" - pun not intended! :-)

main.twig <html><body> {% block %}{% endblock %} {% block b %}{% endblock %} </body></html>  replacea.twig {% block %}hello{% endblock %}  replaceb.twig {% extends "main.twig" %} {% use "replacea.html" %} {% block b %}world{% endblock %} 

check out documentation: http://twig.sensiolabs.org/doc/tags/use.html


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -