可用的 Liquid 類型
Liquid 物件可傳回七種基本類型之一:字串、數字、布林值、陣列、字典、日期時間或 Null。 使用指派或擷取索引標籤來初始化 Liquid 變數。
字串
將文字括在單引號或雙引號中以宣告字串。
{% assign string_a = "Hello World!" %}
{% assign string_b = 'Single quotes work too.' %}
使用 size 屬性取得字串中的字元數。
{{ string_a.size }} <!-- Output: 12 -->
編號
數字可以是整數或浮點。
{% assign pi = 3.14 %}
{% if page.title.size > 100 %}
This page has a long title.
{% endif %}
布林值
布林值是 true 或 false。
{% assign x = true %}
{% assign y = false %}
{% if x %}
This snippet is rendered because x is true.
{% endif %}
陣列
陣列會保存任何類型的值清單。 您可以使用 [ ] 依 (從零開始的) 索引存取特定項目、使用 for 標籤逐一查看這些項目,以及使用 size 屬性取得陣列中的項目數。
{% for view in entitylist.views %}
{{ view.name }}
{% endfor %}
{{ entitylist.views[0] }}
{% if entitylist.views.size > 0 %}
This list has {{ entitylist.views.size }} views.
{% endif %}
Dictionary
字典可保存值的集合,可藉由字串索引鍵存取這些值。 您可以使用 [ ] 依字串索引鍵存取特定項目、使用 for tag 逐一查看這些項目,以及使用 size 屬性取得字典中的項目數。
{{ request.params[ID] }}
{% if request.params.size > 0 %}
The request parameters collection contains some items.
{% endif %}
日期時間
DateTime 物件代表特定日期與時間。
{{ page.modifiedon | date: 'f' }}
Null
Null 表示空值或不存在的值。 任何試圖傳回空值的輸出都不會呈現任何內容。 在條件中它被視為假。
{% if request.params[ID] %}
This snippet renders if the ID request parameter isn't null.
{% endif %}