Liquid是一種模板語言,最初由Shopify開發(fā)用于電子商務(wù)平臺。Liquid主要用于動態(tài)內(nèi)容創(chuàng)建,允許用戶在網(wǎng)站模板中嵌入變量、條件語句、循環(huán)和過濾器等功能,以便根據(jù)特定條件或數(shù)據(jù)生成動態(tài)頁面內(nèi)容。Liquid代碼可分為對象、標記、過濾器,對象告訴Liquid在頁面的哪個位置展示內(nèi)容,標記創(chuàng)造了模板的邏輯和控制流,過濾器改變Liquid對象的輸出。他們被用在輸出上,通過一個|符號分隔。
split 根據(jù)參數(shù)傳入的分隔符將字符串分解為數(shù)組。split?通常被用于將以逗號為分隔符的字符串轉(zhuǎn)換為數(shù)組。 輸入 {% assign beatles = "John, Paul, George, Ringo" | split: ", " %} {% for member in beatles %} {{ member }} {% endfor %} 輸出 John Paul George Ringo
strip 刪除字符串左右兩側(cè)的所有空白符號(包括制表符、空格、換行符)。對于字符串中間的空白符不做任何處理。 Input {{ " So much room for activities! " | strip }} Output So much room for activities!
strip_html 從字符串中刪除所有 HTML 標簽。 輸入 {{ "Have <em>you</em> read <strong>Ulysses</strong>?" | strip_html }} 輸出 Have you read Ulysses?
strip_newlines 從字符串中刪除所有換行字符(newline character)。 輸入 {% capture string_with_newlines %} Hello there {% endcapture %} {{ string_with_newlines | strip_newlines }} 輸出 Hellothere
times 將一個數(shù)乘以另一個數(shù)。 輸入 {{ 3 | times: 2 }} 輸出 6 輸入 {{ 24 | times: 7 }} 輸出 168 輸入 {{ 183.357 | times: 12 }} 輸出 2200.284
truncate truncate?將字符串截短為指定的字符個數(shù)。如果指定的字符數(shù)量小于字符串的長度,則會在字符串末尾添加一個省略號(…) 并將此省略號計入字符個數(shù)中。 輸入 {{ "Ground control to Major Tom." | truncate: 20 }} 輸出 Ground control to... 自定義省略號 truncate?還支持第二個可選參數(shù),用于指定一個字符序列,此字符...
truncatewords 將字符串截短為指定的單詞個數(shù)。如果指定的單詞數(shù)量小于字符串中包含的單詞個數(shù),則會在字符串末尾添加一個省略號(…)。 輸入 {{ "Ground control to Major Tom." | truncatewords: 3 }} 輸出 Ground control to... 自定義省略號 truncatewords?還支持第二個可選參數(shù),用于指定一個字符序列,此字符序列將被添加...
uniq 刪除數(shù)組中的所有冗余項。 輸入 {% assign my_array = "ants, bugs, bees, bugs, ants" | split: ", " %} {{ my_array | uniq | join: ", " }} 輸出 ants, bugs, bees
upcase 將字符串中的每個字符都轉(zhuǎn)換為大寫形式。對于已經(jīng)全是大寫的字符串不做任何操作。 輸入 {{ "Parker Moore" | upcase }} 輸出 PARKER MOORE 輸入 {{ "APPLE" | upcase }} 輸出 APPLE
? Copyright 2023 深圳藍曬科技有限公司. 粵ICP備2023054553號-1