了解 Liquid 運算子

Liquid 可存取所有常用的邏輯和比較運算子。 這些運算子都可以在 ifunless 等標籤中使用。

基本運算子

== 等於
!= 不等於
> 大於
< 小於
>= 大於或等於
<= 小於或等於
或是 條件 A 條件 B
and 條件 A 條件 B

contains

contains 測試字串內是否有子字串存在。

{% if page.title contains 'Product' %}

The title of this page contains the word Product.

{% endif %}

contains 也可以測試字串陣列中是否有某個字串存在。

startswith

startswith 測試字串是否以特定子字串開頭。

{% if page.title startswith 'Profile' %}

This is a profile page.

{% endif %}

endswith

endswith 測試字串是否以特定子字串結尾。

{% if page.title endswith 'Forum' %}

This is a forum page.

{% endif %}

另請參閱