I have an issue with jinja if elif else tags

I want to render my nav menu bar based on the user_role, to do that I used if else statment in my template that way:

{% if user_role == ‘admin’ %}
___{% extends “users/admin_menu.html” %}
{% elif user_role == ‘moderator’ %}
___{% extends “content/moderator_menu.html” %}
{% else %}
___{% extends “base_menu.html” %}
{% endif %}

(the three underlines ‘___’ are not included in my code, they just represents the empty space)

but when I try to render my template I get this error:

Exception Value:
Invalid block tag on line 3: ‘elif’. Did you forget to register or load this tag?

I asked chatgpt and it answers me that jinja2 does not support elif statment, but I am sure it is supported because I am using it elsewhere and it’s functioning correctly,
also when I searched the web I fond 2 similar post with the same error

Solution 1

Django didn’t recognise your starting block tag, because you have a space between the { and the % .

Solution 2

If this is an exact copy of your template, then you have a problem with your formatting.
Your if tag is split across lines - this causes problems with the template rendering engine.

I don’t have neither problems in my code.

I can guess it has something to do with the extends statement cause it should be on the first line I think, but usually when this happen I get error message because of it.

I hope my problem redaction wasn’t that so long and thank you in advance