Jinja2 block nesting issue
I am using jinja2 as a template language in my project. Here is simplified templates structure:
base.html:
{% block content %}{% endblock %} {% block sidebar %}{% endblock %}
content.html:
{% extend 'base.html' %} {% block content %} <div class="content"> Content {% block sidebar %} <div class="sidebar">Sidebar</div> {% sidebar %} </div> {% endblock %}
And the result of content.html render:
<div class="content"> Content <div class="sidebar">Sidebar</div> </div> <div class="sidebar">Sidebar</div>
As you may see, sidebar is present twice at rendered content.html.
Question:
Is there a way to avoid appearance of the sidebar in content, leaving {% block sidebar %} inside {% block content %} ?
Answers
I think your content.html template is invalid - you're clearly positioning sidebar related content inside the content block, so it will allways appear there. Also, your base.html seems invalid as well, it should look more like:
{% block content %}{% endblock %} {% block sidebar %}{% endblock %}