共用方式為


可用的 Liquid 條件運算子

在條件陳述式 (ifunless) 中使用時,有些 Liquid 值被視為 true,有些則視為 false。

在 Liquid 中,null 和布林值 false 都視為 false;其餘一切都視為 true。 例如,空字串和空陣列視為 true。

{% assign empty_string = "" %}
{% if empty_string %}
<p>This will render.</p>
{% endif %}

如果有必要,請使用特殊值空測試空字串和陣列。

{% unless page.title == empty %}
<h1>{{ page.title }}</h1>
{% endunless %}

使用特殊尺寸屬性測試 Liquid 類型的尺寸。

{% if page.children.size > 0 %}
<ul>
{% for child in page.children %}
<li>{{ child.title }}</li>
{% endfor %}
</ul>
{% endif %}

綜合

Operator
×
×
Null ×
String ×
空字串 ×
0 ×
1, 3.14 ×
陣列或字典 ×
空陣列或字典 ×
Object ×

請參閱