Search code examples
djangodjango-modelsdjango-templatesdjango-views

Django templates syntax error when using {% extends %} within if-block


Is there any problem with the syntax in the following code, there is a error as Invalid block tag: 'else'

{% ifequal chat_profile 1 %}
    {% extends "chatprofile/chat_profile1.html" %}
{% else %}
    {% extends "chatprofile/chat_profile.html" %}
{% endifequal %}

Solution

  • The documentation states:

    If you use {% extends %} in a template, it must be the first template tag in that template. Template inheritance won't work, otherwise.

    So consider using a design where you can use {% include %} instead.