Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jinja2 shorthand conditional

Say I have this:

{% if files %}     Update {% else %}     Continue {% endif %} 

In PHP, say, I can write a shorthand conditional, like:

<?php echo $foo ? 'yes' : 'no'; ?> 

Is there then a way I can translate this to work in a jinja2 template:

'yes' if foo else 'no' 
like image 636
Ahmed Nuaman Avatar asked Jan 08 '13 12:01

Ahmed Nuaman


1 Answers

Yes, it's possible to use inline if-expressions:

{{ 'Update' if files else 'Continue' }} 
like image 142
bereal Avatar answered Sep 27 '22 23:09

bereal