Opened 14 years ago

Closed 14 years ago

#14333 closed (wontfix)

Template Ternary Operator

Reported by: scottix Owned by: nobody
Component: Template system Version: 1.2
Severity: Keywords: ternary if
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hey guys new django user here, I really like what you guys are doing.
The feature request I am presenting is small but I think would be a good addition.
I think there needs to a Ternary operator in your template system.

I know you can do

{% if <var1> %}<var1>{% else %}<var2>{% endif %}

Seems a little overkill for just needing to display one variable over the other. My suggestion is create a ternary operator.

{% <var1> ? <var1> : <var2> %}

It could be cut down even more by this.

{% <var1> ? <var2> %}

I think this is a great way to reduce code markup and make it more readable.
Thank you for your time.
Scottix

Change History (1)

comment:1 by Russell Keith-Magee, 14 years ago

Resolution: wontfix
Status: newclosed

Oh, for the love of all that is holy, no. The ?: ternary operator is one of the worst things that C visited on the world. Even if Django's template language *was* a programming language, I'd be -1 to any attempt to introduce this. And it isn't, which gives us another reason.

And, for the record, the second form is really just the {{|default}} filter.

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