dextervip
dextervip

Reputation: 5069

Short if-else django template

I would like to know if is there any way to do a short if-else in the django template such as in php?

  <?=$variable ? 'String for true' : 'String for false'?>

If variable value is true, display String for true otherwise String for false

Upvotes: 7

Views: 10701

Answers (1)

San4ez
San4ez

Reputation: 8251

There is yesno template filter which maps values for true, false.

{{ variable|yesno:'String for true,String for false' }}

Upvotes: 17

Related Questions