Wednesday, 25 September 2013

Avoiding django TemplateSyntaxError if {% block %} is in an if/else/endif?

Avoiding django TemplateSyntaxError if {% block %} is in an if/else/endif?

If I put a {% block xxx %} twice in a template, I understand the error.
But is there a way get django to ignore this error:
{% if foo %}
complex stuff...
{% block content %}
complex stuff...
{% else %}
complex stuff...
{% block content %}
complex stuff...
{% endif %}
It would make my code quite a bit cleaner. Currently with Django 1.5 I get
'TemplateSyntaxError 'block' tag with name 'content' appears more than
once". Of course only one of those blocks can ever be triggered in the
if/else.

No comments:

Post a Comment