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

Need Your Help

Can you have both client certificate security and service identity authentication in azure acs

wcf security azure certificate acs

We have a WCF service which requires a token supplied by azure's acs service and acs is configured to use the in built service identities for authentication.

How to setup Linkedin Autentication with dotnetopenauth on mvc4

asp.net-mvc-4 linkedin dotnetopenauth

I am create a new asp.net website and I need to use a few authentication provider. I easily got all the providers working (thanks to this awesome template and scotts vid). I'm a little stuck with g...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.