> 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="broken://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%2Fgit-blob-3a6138a731d7e8e493c54e04ac84e28d9e73ff33%2F25_04_10_page_condition_1.svg?alt=media" alt="The Page condition icon in GitBook"></picture> **条件内容**.

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

点击后，你可以通过 [条件编辑器](https://gitbook.com/docs/documentation/zh/publish/adaptive-content/adapting-your-content.md#working-with-the-condition-editor)添加条件。你可以将条件编写为一个 [表达式](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/variables-and-expressions.md) ，用于针对网站中定义的数据进行判断。你可以引用 [变量](https://gitbook.com/docs/documentation/zh/chuang-jian-nei-rong/variables-and-expressions.md)中的数据，也可以使用访客通过其 [声明](https://gitbook.com/docs/documentation/zh/publish/adaptive-content/enabling-adaptive-content.md#set-your-visitor-schema).

提供的数据。你还可以定位人类访客或 AI 代理。请参阅 [定位人类访客和 AI 代理](https://gitbook.com/docs/documentation/zh/publish/adaptive-content/adapting-your-content.md#target-human-visitors-and-ai-agents).

了解 [自适应内容](https://gitbook.com/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.
