> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/blocks/conditional-content.md).

# 条件内容

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

### 创建条件内容

要添加条件块，请在编辑器中新起一行，输入 <kbd>/</kbd>，然后选择 <picture><source srcset="/files/QtQtLiYwc1oJj119cgUz" 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&amp;token=31dd334a-5097-4081-915c-db460e610ec6" alt="The Page condition icon in GitBook"></picture> **条件内容**.

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

点击此处将允许你通过 [条件编辑器](/docs/documentation/zh/publish/adaptive-content/adapting-your-content.md#working-with-the-condition-editor)添加条件。你可以将条件写成一个 [表达式](/docs/documentation/zh/chuang-jian-nei-rong/variables-and-expressions.md) ，该表达式会针对你站点中定义的数据运行。你可以引用来自 [变量](/docs/documentation/zh/chuang-jian-nei-rong/variables-and-expressions.md)的数据，或引用来自访问者的 [声明](/docs/documentation/zh/publish/adaptive-content/enabling-adaptive-content.md#set-your-visitor-schema).

你也可以定位人类访问者或 AI 智能体。参见 [定位人类访问者和 AI 智能体](/docs/documentation/zh/publish/adaptive-content/adapting-your-content.md#target-human-visitors-and-ai-agents).

参见 [自适应内容](/docs/documentation/zh/publish/adaptive-content.md) 以了解更多详情。

### 示例

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

此块仅对具有 **不带有** 属性 A 的用户可见。

<a href="https://gitbook.com/docs/create-content/blocks/conditional-content?visitor.example_attribute_A=true" class="button primary">查看带有属性 A 的内容</a>

## Markdown 表示

```markdown
## 示例

{% if visitor.claims.unsigned.example_attribute_A %}
此块仅对**带有**属性 A 的用户可见。
<a href="https://gitbook.com/docs/create-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/create-content/blocks/conditional-content?visitor.example_attribute_A=true" class="button primary">查看带有属性 A 的内容</a>
{% endif %}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/blocks/conditional-content.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
