Opened 4 years ago

Closed 4 years ago

#17348 closed New feature (fixed)

Implement {% elif %} in the template language

Reported by: aaugustin Owned by: aaugustin
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 aaugustin 4 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 4 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Version set to 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 4 years ago by mitar

  • Cc mmitar@… added

comment:3 Changed 4 years ago by russellm

@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 4 years ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:5 Changed 4 years ago by aaugustin

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

Changed 4 years ago by aaugustin

comment:6 Changed 4 years ago by aaugustin

  • Resolution set to fixed
  • Status changed from new to closed

In [17187]:

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

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