Opened 9 years ago

Closed 9 years ago

#17348 closed New feature (fixed)

Implement {% elif %} in the template language

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: Template system Version: master
Severity: Normal Keywords:
Cc: mmitar@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Following a discussion on IRC today, this feature is deemed useful by some, but others think it add too much logic in the templates.

#3100 may be related.

Attachments (1)

17348.patch (7.4 KB) - added by Aymeric Augustin 9 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 9 years ago by Aymeric Augustin

Triage Stage: UnreviewedAccepted
Version: SVN

#3100 is about supporting arguments on intermediate tag tokens, and it's a pre-requisite for this ticket.

Here are the arguments I saw on IRC.


  • templates should be able to express presentational logic: for instance, depending of an object's state, I want to show different properties
  • the most straightforward workaround is messy: {% if a %} ... {% else %}{% if b %} ... {% else %}{% if c %} ... {% endif %}{% endif %}{% endif %}
  • a more elaborate workaround involves partial templates, e.g. {% include myobj.state_template %} where state_template returns "partials/state_<STATE>.html", but that's overkill for simple cases


  • templates shouldn't contain too much logic — that's a well understood design choice
  • increasing the amount of logic in the templates doesn't help us fight performance issues

Tentatively marking as accepted, please bump back to DDN if you disagree.

comment:2 Changed 9 years ago by Mitar

Cc: mmitar@… added

comment:3 Changed 9 years ago by Russell Keith-Magee

@aaugustin -- Count me as +1 on this; I can't see any argument where massively nested ifs are preferable to a flat series of {% elif %} statements. I don't think this increases the amount of logic in a template; it just makes the logic that we've already allowed slightly more friendly.

comment:4 Changed 9 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin

comment:5 Changed 9 years ago by Aymeric Augustin

Attached patch implements {% elif %}. It complements 3100-backwards-compatible.patch from #3100.

Changed 9 years ago by Aymeric Augustin

Attachment: 17348.patch added

comment:6 Changed 9 years ago by Aymeric Augustin

Resolution: fixed
Status: newclosed

In [17187]:

Fixed #17348 -- Implemented {% elif %}. Refs #3100.

Note: See TracTickets for help on using tickets.
Back to Top