小枝数字代替文本

时间:2018-07-18 11:49:43

标签: twig

taxsAmountData数组中有项目,

array: 4 [
"netAmount" => 1000.0
"taxRate" => "zw"
"taxAmount" => 0.0
"grossAmount" => 1000.0
]

array: 4 [
"netAmount" => 1000.0
"taxRate" => 0
"taxAmount" => 0.0
"grossAmount" => 1000.0
]

当我想在循环中显示值时,出现一个奇怪的错误,即不是“ zw”,而是0。如果这样做,更糟的是:

{% for taxAmountsData in taxesAmountData}
{% if taxAmountsData.taxRate == 'zw'}
         i have zw
{% elseif taxAmountsData.taxRate == 0}
         i have 0
{% endif%}
{% endfor%}

它告诉我2x我有0,并将其视为另一个0

1 个答案:

答案 0 :(得分:-1)

不确定是否是复制粘贴错误,但是您错过了在标签上关闭%的情况:

尝试:

{% for taxAmountsData in taxesAmountData %}
    {% if taxAmountsData.taxRate == 'zw' %}
        i have zw
    {% elseif taxAmountsData.taxRate == 0 %}
        i have 0
    {% endif %}
{% endfor %}