> 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/reusable-content.md).

# 可复用内容

可重用内容可让你在多个页面和部分之间同步内容，因此你可以同时编辑该块的所有实例。

<figure><img src="/files/04929e36cedac0101f0b5177f8945147b5261639" alt="A GitBook screenshot showing reusable content"><figcaption><p>在某个部分中创建可重用内容。</p></figcaption></figure>

## 基础知识

可重用内容的工作方式与其他内容完全相同——你可以通过变更请求对其进行修改，将其纳入审阅工作流，并且它会在任何已发布的网站上正确渲染。

虽然可重用内容可以在多个部分中被引用，但它只属于一个 *父部分*.

### “父部分”概念

父部分是拥有该可重用内容的部分。这是唯一可以编辑该内容的地方。

尽管对可重用内容的更新会立即出现在所有实例中，但所有更改都必须源自父部分——无论是直接编辑还是通过变更请求。

部分同时支持编辑工作流和安全性。由于 GitBook 强制基于权限的编辑，可重用内容只能从其父部分进行更改。这确保了即使内容在整个组织内被重复使用，编辑权限也能得到尊重。

### 已知限制

#### 集成

集成提供的块不支持用于可重用内容。这是因为 GitBook 中的集成是按部分安装的，而限制访问可确保第三方集成仅拥有你授予的权限。在各部分之间引用可重用内容会破坏这一安全边界。

#### 搜索

目前，可重用内容仅会在其父部分内的搜索结果中显示。我们正在积极努力消除这一限制，以便可重用内容在被引用的任何地方都能出现在搜索结果中。

## 在应用中

### **创建可重用内容**

要创建可重用内容，请选择一个或多个块，然后打开 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt="The Actions menu icon in GitBook"></picture> ，选择 **转换为**，然后选择 **可重用内容**。你还可以为你的块命名，以便之后更容易查找和重复使用。

或者，你也可以选择一个或多个块，然后按 **Cmd + C** ，以打开一个提示，询问你是否要创建可重用内容。

### **插入可重用内容**

你可以像插入任何其他块一样插入可重用内容。按 `/` 在空白行上以打开 **插入面板**。你也可以点击任意块或空白行旁边的 `+` 。

页面侧边栏中的可重用内容面板会列出当前部分中之前创建的内容块。

要从当前部分或其他部分插入可重用内容，你可以访问：

1. 从 **插入面板** 或者 `+` 菜单。
2. 使用顶部的部分选择器选择源部分。
3. 按名称搜索可重用块，然后选择它以插入。

从其他部分插入内容不会转移所有权。只有父部分可以编辑该可重用内容。来自该父部分的更新会继续同步到每个实例。

### **编辑可重用内容**

可重用内容与其他内容类似——如果启用了实时编辑，你可以直接编辑任一实例；如果没有启用，则可通过变更请求编辑。你所做的任何更改都会同步到该内容被使用的所有位置。

如果你是在变更请求中进行更改，那么当该变更请求合并后，内容会同步到所有其他实例。

### **分离可重用内容**

你可以通过打开 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt="The Actions menu icon in GitBook"></picture> 并选择 **分离**。分离会将内容转换回普通块。

一旦分离，你对该块（或这些块）所做的任何更改都不会反映到其他实例中，而你在那些实例中所做的更改也不会反映到已分离的块（或这些块）中。可重用内容的所有其他实例仍会彼此同步。

### 删除可重用内容

如果你愿意，可以从你的部分中完全删除可重用内容。在页面的目录中找到该可重用内容，然后打开 **操作菜单** <picture><source srcset="/files/YjlF3Z9KMYv9aQiFzZKD" media="(prefers-color-scheme: dark)"><img src="/files/d05670ba93b683794fb3fe95a9fc7ab5c7fceafd" alt="The Actions menu icon in GitBook"></picture> 位于你想删除的内容旁边的 **删除**.

删除可重用内容将会 **将其从所有使用它的页面中删除**。此操作无法撤销。

## 与 GitHub 和 GitLab 同步

同步到 GitHub 和 GitLab 时完全支持可重用内容。你的可重用内容将被导出到一个专用 `包括` 文件夹中，每个内容都是一个单独的 Markdown 文件。

然后，你的其他页面会使用 `包括` 指令引用你的内容。

{% hint style="info" %}
同步时， `.gitbook/includes` 目录会在每个已同步部分的根目录中创建（它可能不是整个仓库的根目录）。如果你的 `.gitbook/includes` 文件夹或其文件出现在你部分的目录中，你可能需要在目录中手动将它们隐藏。
{% endhint %}

#### 示例

{% hint style="success" %}
如果你是在 GitHub 端编写，请确保 include 的路径相对于包含该引用的文件，而不是仓库根目录。
{% endhint %}

```markdown
{% include "../../.gitbook/includes/reusable-block.md" %}
```


---

# 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 dynamically by asking a question.

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

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
