Opened 12 years ago

Closed 12 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: dev
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

Description

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 12 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Aymeric Augustin, 12 years ago

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.

Pros:

  • 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

Cons:

  • 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 by Mitar, 12 years ago

Cc: mmitar@… added

comment:3 by Russell Keith-Magee, 12 years ago

@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 by Aymeric Augustin, 12 years ago

Owner: changed from nobody to Aymeric Augustin

comment:5 by Aymeric Augustin, 12 years ago

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

by Aymeric Augustin, 12 years ago

Attachment: 17348.patch added

comment:6 by Aymeric Augustin, 12 years ago

Resolution: fixed
Status: newclosed

In [17187]:

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

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