In my Symfony2/twig webapp I have a twig template, that only contains a <div id="#container">...</div>
, no <html></html>
wrapping. I use this for an ajax call where I embed this into my page layout. Let's call this layout ajax_template.html.twig
.
<h1>Headline</h1>
{% block my_content %}
<p>My content</p>
{% endblock %}
Now I have another template, that shall extend the ajax_template.html.twig
. But this page is not called via ajax, but directly. So it shall also extend my base_layout.html.twig
, where all the <html></html>
wrapping is included. Should be something like:
# won't work because no multiple inheritance supported
{% extends 'MyBundle::base_layout.html.twig' %}
{% extends 'MyBundle:MyController:ajax_template.html.twig' %}
{% block my_content %}
<p>My modified content</p>
{% endblock %}
Already tried a couple of methods, e.g. include()
or use()
in my twig templates. I also had a check, if the current path is an ajax call:
{% if '/ajax/' in path(app.request.attributes.get('_route')) %}
{% extends 'MyBundle::base_layout.html.twig' %}
{% endif %}
But none of my approaches work. Do you have any ideas?