标签
Liquid tags 用于定义告知 template 执行操作的逻辑。
条件标签
Conditional tags 定义决定 Liquid 代码块是否执行的条件。
迭代标签
Iteration tags 反复执行代码块。
Theme 标签
Theme tags 用于分配或渲染属于您的 theme 的内容。
Variable 标签
Variable tags 使您能够创建新的 Liquid 变量。
使用方式
Tags 使用花括号百分号分隔符 {% %} 包裹。分隔符内的文本在渲染时不会产生可见输出。
在下面的示例中,if tag 定义了需要满足的条件。如果 product.available 返回 true,则显示价格;否则显示"售罄"提示。
{% if product.available %}
Price: $12.88
{% else %}
Sorry, this product is sold out.
{% endif %}
{
"product": {
"available": true
}
}
Price: $12.88
带参数的 tags
某些 tags 接受参数。有些参数是必填的,有些是可选的。例如,for tag 可以接受 limit 参数,在特定索引处退出循环。
{% assign numbers = '1,2,3,4,5' | split: ',' %}
{% for item in numbers limit: 2 %}
{{ item }}
{% endfor %}
1
2