Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 366
dextervip Avatar asked May 11 '12 06:05

dextervip


Video Answer


1 Answers

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

{{ variable|yesno:'String for true,String for false' }}
like image 55
San4ez Avatar answered Oct 22 '22 16:10

San4ez