# 条件内容

条件内容块可让你根据用户数据和变量，控制页面上哪些人可以看到某个内容块。这些变量可以通过 cookie、功能标志、已认证访问或 URL 参数传入。

### 创建条件内容

要添加条件块，请在编辑器中新起一行，输入 <kbd>/</kbd>，然后选择 <picture><source srcset="broken-reference" media="(prefers-color-scheme: dark)"><img src="https://2111890564-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNkEGS7hzeqa35sMXQZ4X%2Fuploads%2F51vQZhUqnkdsYpyUo1Pj%2Fpage-condition.svg?alt=media&#x26;token=31dd334a-5097-4081-915c-db460e610ec6" alt="The Page condition icon in GitBook"></picture> **条件内容**.

插入该块后，点击该块右上角的红色条件徽章。

点击此处将允许你通过 [条件编辑器](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/zh/publishing-documentation/adaptive-content/adapting-your-content#working-with-the-condition-editor)添加一个条件。你可以将条件写成一个 [表达式](https://gitbook.com/docs/creating-content/variables-and-expressions) ，它会针对你站点中定义的数据运行。你可以引用来自 [变量](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/zh/creating-content/variables-and-expressions)的数据，或来自访问者通过其 [声明](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/zh/publishing-documentation/adaptive-content/enabling-adaptive-content#set-your-visitor-schema).

参见 [自适应内容](https://gitbook-open-v2-preview.gitbook.workers.dev/url/gitbook.com/docs/documentation/zh/publishing-documentation/adaptive-content) 的更多详情。

### 示例

下面的示例使用从按钮链接的 URL 参数来控制哪个条件内容块可见。

{% if visitor.claims.unsigned.example\_attribute\_A %}
此块仅对用户可见 **具有** 属性 A。

<a href="https://gitbook.com/docs/creating-content/blocks/conditional-content?visitor.example_attribute_A=false" class="button primary">查看没有属性 A 的版本</a>
{% endif %}

{% if !visitor.claims.unsigned.example\_attribute\_A %}
此块仅对用户可见 **没有** 属性 A。

<a href="https://gitbook.com/docs/creating-content/blocks/conditional-content?visitor.example_attribute_A=true" class="button primary">查看具有属性 A 的版本</a>
{% endif %}

## 在 Markdown 中的表示

```markdown
## 示例

{% if visitor.claims.unsigned.example_attribute_A %}
此块仅对**具有**属性 A 的用户可见。
<a href="https://gitbook.com/docs/creating-content/blocks/conditional-content?visitor.example_attribute_A=false" class="button primary">查看没有属性 A 的版本</a>
{% endif %}

{% if !visitor.claims.unsigned.example_attribute_A %}
此块仅对**没有**属性 A 的用户可见。
<a href="https://gitbook.com/docs/creating-content/blocks/conditional-content?visitor.example_attribute_A=true" class="button primary">查看具有属性 A 的版本</a>
{% endif %}
```
