Twig是否支持三元(简写为if-else)运算符?
我需要一些条件逻辑,比如:
{%if ability.id in company_abilities %}
<tr class="selected">
{%else%}
<tr>
{%endif%}
但在Twig中使用速记。
发布于 2012-08-06 05:51:15
{{ (ability.id in company_abilities) ? 'selected' : '' }}
三元运算符记录在'other operators‘下
发布于 2014-07-21 15:32:29
您可以从Twig 1.12.0开始使用速记语法
{{ foo ?: 'no' }} is the same as {{ foo ? foo : 'no' }}
{{ foo ? 'yes' }} is the same as {{ foo ? 'yes' : '' }}
发布于 2021-03-31 10:39:40
例如,如果价格存在于数据库中,那么print (价格为$$$)、else print (不可用)和~
用于Twig
中的连接。
{{ Price ? 'Price is '~Price : 'Not Available' }}
https://stackoverflow.com/questions/11820297
复制相似问题