# 条件内容

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

### 创建条件内容

要添加条件区块，请在编辑器中另起一行，输入 <kbd>/</kbd>，然后选择 <picture><source srcset="/files/QtQtLiYwc1oJj119cgUz" media="(prefers-color-scheme: dark)"><img src="/files/9462b24994b3e1c747496948ae8aafda4b33014f" alt="The Page condition icon in GitBook"></picture> **条件内容**.

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

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

参见 [自适应内容](/docs/documentation/zh/zhan-dian-fang-wen/adaptive-content.md) 。

### 示例

下面的示例使用从按钮链接的 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 %}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitbook.com/docs/documentation/zh/creating-content/blocks/conditional-content.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
