symfony - Many conditions if true in twig -


i have many attributes boolean type , if true show yes else show no. shall condition "if" each attribute or there other short method ?

you can use ternary operator achieve shorter if-syntax in twig.

example:

# i'm creating example array here  {% set user = { 'active' : true } %}  # now, instead of ...  user {% if user.active %}active{% else %}inactive{% endif %}.  # ... can write:  user {{ user.active ? 'active' : 'inactive' }}. 

output:

user active.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -