1đź‘Ť
Firstly, that’s not how assignment tags work. You have never actually called the tag; if partner
refers to a (non-existent) template variable named “partner”. You call an assignment tag by using it on its own along with a variable to assign it to:
{% partner as partner_value %}
{% if partner_value %}...{% endif %}
Secondly, that’s not how blocks work either. You can’t dynamically define blocks; they are part of the basic structure of a template, not something that is assigned during evaluation.
👤Daniel Roseman
0đź‘Ť
I accomplished this by using a context_processor
(https://docs.djangoproject.com/en/1.7/ref/settings/#std:setting-TEMPLATE_CONTEXT_PROCESSORS)
Context Processor:
def partners(context):
return {
'partner': False
}
Template:
{% block header %}
{% if partner %}
{% include 'includes/partner_header.djhtml' %}
{% else %}
{{ block.super }}
{% endif %}
{% endblock header %}
{% block footer %}
{% if partner %}
{% include 'includes/partner_footer.djhtml' %}
{% else %}
{{ block.super }}
{% endif %}
{% endblock footer %}
👤thatgibbyguy
- How to make report by export data into PDF file in django?
- Handling JSON Response With Django
- NoReverseMatch when rendering page
Source:stackexchange.com