Jekyll Liquid If-Or-Condition 为 False,即使两个条件之一应该返回 true

问题描述 投票:0回答:0

总而言之,我有一个数组,其中包含几个如下所示的数组:

[0, 1, 2, 3, {'key': 'example', 'id': 0}]
.

我有一个看起来像这样的循环:

{% for arr in array %} // Array including the array I showed above
  {% for item in arr %} // Array of pattern I showed above

    {% if item.key == key and item.id == id %}
      If-1 True
    {% else %}
      If-2 False
    {% endif %}

    {% if (elem == key and item == id) or (item.key == key and item.id == id %}
      If-2 True
    {% else %}
      If-2 False
    {% endif %}

  {% endloop %}
{% endloop %}

如您所见,第二个 If 语句包括第一个 If 语句的条件,以及第二个条件之间的

or
。根据我过去的编程经验,这应该意味着如果两个条件中的任何一个是
true
,整个If语句应该是
true

然而这里不是这样的。当第二个语句仍然返回

If-1 True
字符串时,第一个语句将返回
If-2 False
字符串。

为什么会这样?

or
在 Liquid 中的工作方式不同吗?

jekyll liquid
© www.soinside.com 2019 - 2024. All rights reserved.