【发布时间】:2015-07-04 02:37:54
【问题描述】:
我有用 TWIG 编写的脚本。
Weight: {{ doc.weight }} kgs<br />
// 这部分脚本仅在“detail”和“info” MySQL 字段不为空时显示文本信息
{% if "" == doc.info_hl %}
{% if '' != doc.detail_code %}
<b>Info: {{ doc.info }}</b>
{% endif %}
{% else %}
Info: {{ doc.info_hl|raw }}
{% endif %}
<br />
{% if "" == doc.detail_code_hl %}
{% if '' != doc.detail_code %}
<b>Details: {{ doc.detail_code }}</b>
{% endif %}
{% else %}
<b>Details: {{ doc.detail_code_hl|raw }}</b>
{% endif %}
有时 MySQL 字段“权重”的值为“0.00”
如何修改上面的代码 - DO NOT SHOW "weight" MySQL field IF value in this field "0.00" ? 我们可以在上面看到我们如何使用空文本字段来做到这一点,但是如何使用等于“0.00”的十进制字段来做到这一点?
提前感谢任何提示尝试!
【问题讨论】:
-
我在您的代码中没有看到
weight。请提供相关代码块以提供更多上下文,并表现出为解决您的问题所做的真诚努力。 -
重量:{{ doc.weight }} kgs
- 在上面代码的开头! -
@Ninir 你是说
{% if "0.00" == doc.weight %} {% if '' != doc.weight %} Weight: {{ doc.weight }} kgs -
我的意思是
{% if '0.00' == doc.weight %} Weight: {{ doc.weight }} kgs {% endif %}。根据您要检查的值,以上将适合您的需求。但是,Mike 说得对,如果要检查 doc.weight 不为空也不为 0,那么检查{% if doc.weight is not empty %}Weight: {{ doc.weight }} kgs {% endif %}会更好 -
@Ninir 它可以工作
{% if '0.00' == doc.weight %} Weight: {{ doc.weight }} kgs {% endif %}但反之亦然 - 它显示所有重量为“0.00”的位置,而不显示所有其他位置。它非常接近我正在寻找的解决方案 - 但我需要一些东西{% if NOT '0.00' == doc.weight %}...但我找不到这样的 TWIG 语法“如果不是”..