Code

Opened 2 years ago

Closed 2 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

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 aaugustin 2 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 2 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.

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 Changed 2 years ago by mitar

  • Cc mmitar@… added

comment:3 Changed 2 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 2 years ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:5 Changed 2 years ago by aaugustin

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

Changed 2 years ago by aaugustin

comment:6 Changed 2 years ago by aaugustin

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

In [17187]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.