Tuesday, 27 August 2013

Django: making {% block "div" %} conditional with a conditional {% extends %}

Django: making {% block "div" %} conditional with a conditional {% extends %}

I would like to share a template between AJAX and regualr HTTP calls, the
only difference is that one template needs to extend base.html html, while
the other dose not.
I can use
{% extends request.is_ajax|yesno:"app/base_ajax.html,app/base.html" %}
To dynamically decide when to extend, but I also need to include {% block
'some_div' %}{% endbock %} tags to tell the renderer where to put my
content. The ajax call needs those tags to be left out because jQuery
tells it where to put the content with $('somediv').html(response).
Any idea on how to dynamically include those block tags when its not an
ajax call?
I've been referencing this question to figure it out:
Any way to make {% extends '...' %} conditional? - Django
Attempt to make it work through an {% if %}:
{% extends request.is_ajax|yesno:",stamped/home.html" %}
{% if request.is_ajax == False%}
{% block results %}
{% endif %}
{% load stamped_custom_tags %}
...
Content
...
{% if request.is_ajax == False%}
{% endblock %}
{% endif %}
but this fails when parser runs into the {% endif %}

No comments:

Post a Comment