Liquid模板語言
Liquid是一種模板語言,最初由Shopify開發(fā)用于電子商務平臺。Liquid主要用于動態(tài)內容創(chuàng)建,允許用戶在網站模板中嵌入變量、條件語句、循環(huán)和過濾器等功能,以便根據特定條件或數據生成動態(tài)頁面內容。Liquid代碼可分為對象、標記、過濾器,對象告訴Liquid在頁面的哪個位置展示內容,標記創(chuàng)造了模板的邏輯和控制流,過濾器改變Liquid對象的輸出。他們被用在輸出上,通過一個|符號分隔。
Liquid是一種模板語言,最初由Shopify開發(fā)用于電子商務平臺。Liquid主要用于動態(tài)內容創(chuàng)建,允許用戶在網站模板中嵌入變量、條件語句、循環(huán)和過濾器等功能,以便根據特定條件或數據生成動態(tài)頁面內容。Liquid代碼可分為對象、標記、過濾器,對象告訴Liquid在頁面的哪個位置展示內容,標記創(chuàng)造了模板的邏輯和控制流,過濾器改變Liquid對象的輸出。他們被用在輸出上,通過一個|符號分隔。
lstrip 刪除字符串左側的所有空白符(制表符、空格和換行符)。字符串中間的所有空白符不受影響。 輸入 {{ " So much room for activities! " | lstrip }} 輸出 So much room for activities!
map 從對象(object)中提取指定名稱的屬性的值,并用這些值構建一個數組。 以下實例中,假定?site.pages?包含了整個網站的元數據信息。利用?assign?和?map?過濾器創(chuàng)建一個變量,此變量只包含?site.pages?對象中?category?屬性對應的所有值。 輸入 {% assign all_categories = site.pages | map: "category" %} {% for item i...
minus 從一個數中減去另一個數。 輸入 {{ 4 | minus: 2 }} 輸出 2 輸入 {{ 16 | minus: 4 }} 輸出 12 輸入 {{ 183.357 | minus: 12 }} 輸出 171.357
modulo 返回除法運算的余數。 輸入 {{ 3 | modulo: 2 }} 輸出 1 輸入 {{ 24 | modulo: 7 }} 輸出 3 輸入 {{ 183.357 | modulo: 12 }} 輸出 3.357
newline_to_br 將所有換行符(n) 替換為 HTML 的 (<br>) 標簽。 輸入 {% capture string_with_newlines %} Hello there {% endcapture %} {{ string_with_newlines | newline_to_br }} 輸出 <br /> Hello<br /> there<br />
plus 兩個數相加。 輸入 {{ 4 | plus: 2 }} 輸出 6 輸入 {{ 16 | plus: 4 }} 輸出 20 輸入 {{ 183.357 | plus: 12 }} 輸出 195.357
prepend 在一個字符串前面附加另一個字符串。 輸入 {{ "apples, oranges, and bananas" | prepend: "Some fruit: " }} 輸出 Some fruit: apples, oranges, and bananas prepend?也能作用于變量: 輸入 {% assign url = "example.com" %} {{ "/index.html" | prepend: url }} 輸出 example.com/index.html
remove 從一個字符串中刪除所有出現的另一個子字符串。 輸入 {{ "I strained to see the train through the rain" | remove: "rain" }} 輸出 I sted to see the t through the
remove_first 從一個字符串中僅僅刪除第一次出現的另一個子字符串。 輸入 {{ "I strained to see the train through the rain" | remove_first: "rain" }} 輸出 I sted to see the train through the rain
? Copyright 2023 深圳藍曬科技有限公司. 粵ICP備2023054553號-1