I have been trying to call a block inside an if condition in django template.
I have a base template. I have many other templates that extend the base template.
I have defined a block in base template:
{% block test_block %}Test{% endblock %}
I then want to override this block on a certain condition in the other templates. If the condition fails, the block shouldn't get overridden. This is something what I have written:
{% if test_value %}{% block test_block %}Development{% endblock %}{% endif %}
This actually (or may be virtually) ignores the if condition.
What I finally did:
{% block test_block %}{% if test_value %}Development{% else %}{{ block.super }}{% endif %}{% endblock %}
I had to do something like this everywhere it was required.
Is this the best way? Is this the only way? Why can't I try the first way of mine? Or is there any mistake from my side?