# 标签

> Liquid tags 如何定义 Shoplazza Theme 模板的逻辑：tag 的写法、带参数的 tag，以及条件、迭代、语法、主题、变量五类标签。

Liquid tags 用于定义告知 template 执行操作的逻辑。

## 使用方式

Tags 使用花括号百分号分隔符 `{% %}` 包裹。分隔符内的文本在渲染时不会产生可见输出。

在下面的示例中，`if` tag 定义了需要满足的条件。如果 `product.available` 返回 `true`，则显示价格；否则显示"售罄"提示。

```liquid title="代码"
{% if product.available %}
	Price: $12.88
{% else %}
	Sorry, this product is sold out.
{% endif %}
```
```json title="数据"
{
  "product": {
    "available": true
  }
}
```

```html title="输出"
Price: $12.88
```

## 带参数的 tags

某些 tags 接受参数。有些参数是必填的，有些是可选的。例如，`for` tag 可以接受 `limit` 参数，在特定索引处退出循环。

```liquid title="代码"
{% assign numbers = '1,2,3,4,5' | split: ',' %}

{% for item in numbers limit: 2 %}
  {{ item }}
{% endfor %}
```

```html title="输出"
1
2
```
