Skip to main content

内容类型构建器

🌐 Content-type Builder

Page summary:

内容类型构建器是用于设计内容类型和组件的工具。本指南概述了内容类型构建器,并涵盖字段选项、关联关系、组件使用,以及分享数据建模技巧。

内容类型构建器中,用户可以创建和编辑他们的内容类型,该构建器可通过管理面板的主导航访问。

IDENTITY CARD
角色与权限
在“角色 > 插件 - 内容类型构建器”中最低“读取”权限。
环境
仅在开发环境中可用。

概览

🌐 Overview

The 内容类型构建器允许创建和管理内容类型,这些内容类型可以是:

  • 集合类型:可以管理多个条目的内容类型。
  • 单一类型:只能管理一个条目的内容类型。
  • 组件:可用于多种集合类型和单一类型的内容结构。尽管它们从技术上讲不是正真的内容类型,因为它们不能独立存在,但组件也是通过内容类型构建器创建和管理的,与集合类型和单一类型的方式相同。

所有三者都显示为 内容类型构建器子导航中的类别。在每个类别中列出了所有已创建的内容类型和组件。

Tip

点击 内容类型构建器子导航中的搜索图标 以查找特定的集合类型、单一类型或组件。

在内容类型构建器的子导航中,还显示了一个集中式的 保存 按钮,适用于所有内容类型和组件。随着内容类型/组件和字段状态的显示,这使你可以同时处理多个内容类型和组件。可以显示以下状态:

🌐 In the Content-type Builder's sub navigation is also displayed a centralised Save button that applies for all content-types and components. Along with the display of statuses for both content-types/components and fields, this allows you to work on several content-types and components at the same time. The following statuses can be displayed:

  • NewN 表示某个内容类型/组件或字段是新的,尚未保存,
  • ModifiedM 表示自上次保存以来内容类型/组件或字段已被修改,
  • DeletedD 表示某个内容类型/组件或字段已被删除,但只有在保存后才会得到确认。
Note

点击 保存 按钮旁边的 按钮可以访问其他选项,例如 撤销/重做上一次更改放弃所有更改。这些选项也是集中化的,这意味着它们适用于自上次保存以来在所有内容类型、组件和字段上所做的最后操作。

🌐 Clicking on the ... button next to Save gives access to other options, such as Undo/Redo last change and Discard all changes. These options are also centralised, meaning that they apply to the last action(s) that was/were done on all content-types, components and fields since the last time you saved.

使用

🌐 Usage


创建内容类型

🌐 Creating content-types

内容类型构建器允许创建新的内容类型:单一类型和集合类型,也包括组件。

🌐 The Content-type Builder allows to create new content-types: single and collection types, but also components.

使用 Strapi AI 创建内容类型 NewThis content is new.

🌐 Creating content-types with Strapi AI NewThis content is new.

GrowthThis feature is available with a Growth plan.

启用时,Strapi AI 会添加一个助手,帮助你使用自然语言创建或编辑内容类型。

要在内容类型构建器中使用 Strapi AI,请点击管理面板右下角的 按钮,并描述你需要的内容:

Strapi AI in Content-Type BuilderStrapi AI in Content-Type Builder

你还可以使用聊天窗口底部的 按钮,从现有的 Strapi 或前端应用导入代码,导入 Figma 项目,或附加图片以从设计中提取内容结构。

Tip

你的提示越精确,你创建的模式就越准确。

🌐 The more precise your prompts, the more accurate your created schemas are likely to be.

例如,以下提示示例在创建关系时效果很好:Could you please generate a collection of dogs then also generate an owner collection and add relationship to dogs? An owner can have multiple dogs, but a dog can only have one owner.

Strapi AI credits

Strapi AI 在 Growth 计划中每月包含 1,000 个积分,并且在免费试用期间提供 10 个免费积分。轻量级操作使用较少积分,而更复杂的操作使用更多积分。

你可以在管理面板的 Settings Overview 中查看你的信用使用情况。当你的使用量达到月度配额的80%、90%和100%时,将会发送通知。

当你的 Growth 套餐积分用完后,你可以继续使用 Strapi AI,超出部分将按月计费。

有关 Strapi AI 的更多信息,请参阅专门的支持文章

🌐 For more information about Strapi AI, please refer to the dedicated support article.

手动创建内容类型

🌐 Creating content-types manually

Content-type creationContent-type creation
  1. 选择是要创建集合类型还是单一类型。
  2. 内容类型构建器的你想要创建的内容类型类别中,点击 创建新集合/单一类型
  3. 在内容类型创建窗口中,在显示名称文本框中输入新内容类型的名称。
  4. 检查API ID以确保自动填充的值是正确的。在内容管理器中显示时,集合类型名称确实会自动变为复数形式。建议使用单数名称,但API ID字段可以用于修复任何复数化错误。
  5. (可选)在高级设置标签中,为新内容类型配置可用设置: | 设置名称 | 说明 ||---------|-----|| 草稿与发布 | 勾选此复选框以允许内容类型的条目在发布之前以草稿版本进行管理(参见 草稿与发布)。 || 国际化 | 勾选此复选框以允许内容类型的条目被翻译为其他地区版本。 |
  6. 点击 继续 按钮。
  7. 为你的内容类型添加并配置所选字段(见 为内容类型配置字段)。
  8. 点击 保存 按钮。
Caution

新的内容类型只有在保存后才被视为已创建。只有在至少添加了一个字段并正确配置后,才能保存。如果未完成这些步骤,则无法创建内容类型,也无法在内容类型构建器中将其列在所属类别中,也无法在 内容管理器 中使用。

🌐 New content-types are only considered created once they have been saved. Saving is only possible if at least one field has been added and properly configured. If these steps have not been done, a content-type cannot be created, listed in its category in the Content-type Builder, and cannot be used in the Content Manager.

新组件

🌐 New component

Component creationComponent creation
  1. 内容类型构建器子导航的组件类别中,点击 创建新组件
  2. 在组件创建窗口中,配置新组件的基本设置:
    • 显示名称文本框中输入组件名称。
    • 选择一个可用类别,或在文本框中输入新类别名称来创建类别。
    • (可选) 选择一个代表新组件的图标。你可以使用搜索 来查找图标,而不是滚动浏览列表。
  3. 点击 继续 按钮。
  4. 为你的组件添加并配置所选字段(参见 为内容类型配置字段)。
  5. 点击 保存 按钮。

编辑内容类型

🌐 Editing content-types

内容类型构建器允许管理所有现有的内容类型。对于选定的要编辑的内容类型或组件,内容类型构建器界面的右侧显示所有可用的编辑和管理选项。

🌐 The Content-type Builder allows to manage all existing content-types. For an chosen content-type or component to edit, the right side of the Content-type Builder interface displays all available editing and management options.

Content-type Builder's edition interfaceContent-type Builder's edition interface

设置

🌐 Settings

  1. 点击你的内容类型的 编辑按钮以访问其设置。
  2. 编辑你选择的可用设置:
Content-type Builder's basic settingsContent-type Builder's basic settings
  • 显示名称:内容类型或组件在管理面板中显示的名称。
  • API ID(单数):内容类型或组件在 API 中使用的名称。它是由显示名称自动生成的,但可以编辑。
  • API ID(复数):内容类型或组件在 API 中使用的复数名称。它是从显示名称自动生成的,但可以进行编辑。
  • 类型:内容类型或组件的类型。它可以是集合类型单一类型
  1. 在对话框中点击 完成 按钮。
  2. 在内容类型构建器导航中点击保存按钮。

字段

🌐 Fields

从列出内容类型字段的表格中,你可以:

🌐 From the table that lists the fields of your content-type, you can:

  • 点击 按钮以访问字段的基本和高级设置并进行编辑
  • 点击 添加另一个字段 按钮,为所选内容类型创建新字段
  • 点击 按钮,然后拖放任意字段以重新排序内容类型的字段
  • 点击 按钮以删除字段
Caution

编辑字段允许重命名它。然而,请记住,对于数据库来说,重命名字段意味着创建一个全新的字段并删除原来的字段。尽管数据库中的内容不会被删除,但与原字段名称相关的数据将无法再通过应用的管理面板访问。

🌐 Editing a field allows renaming it. However, keep in mind that regarding the database, renaming a field means creating a whole new field and deleting the former one. Although nothing is deleted from the database, the data that was associated with the former field name will not be accessible from the admin panel of your application anymore.

配置内容类型字段

🌐 Configuring content-types fields

内容类型由一个或多个字段组成。每个字段旨在包含特定类型的数据,这些数据在内容管理器中填写(参见 创建与编写内容)。

🌐 Content-types are composed of one or several fields. Each field is designed to contain specific kind of data, filled up in the Content Manager (see Creating & Writing content).

内容类型构建器中,可以在创建新的内容类型或组件时添加字段,也可以在编辑或更新内容类型或组件时添加字段。

Note

根据创建或编辑的内容类型或组件,并非所有字段(包括组件和动态区域)始终可用。

🌐 Depending on what content-type or component is being created or edited, not all fields -including components and dynamic zones- are always available.

Fields selectionFields selection

文本

文本字段显示一个可以包含小文本的文本框。该字段可用于标题、描述等。

🌐 The Text field displays a textbox that can contain small text. This field can be used for titles, descriptions, etc.

| 设置名称 | 说明 ||--------------|---------------------------------------------------------------------------------------------------------|| 名称 | 填写文本字段的名称。 || 类型 | 在 短文本(最多255个字符) 和 长文本之间选择,以提供更多或更少的空间填写文本字段。 |

富文本(块)

富文本(块)字段显示一个带有实时渲染和各种选项的编辑器,用于管理富文本。此字段可用于较长的书面内容,甚至包括图片和代码。

🌐 The Rich Text (Blocks) field displays an editor with live rendering and various options to manage rich text. This field can be used for long written content, even including images and code.

| 设置名称 | 使用说明 ||--------------|-------------------------------------------------|| 名称 | 写入富文本(区块)字段的名称。 |

React renderer

如果使用积木编辑器,我们建议你也使用 Strapi Blocks React Renderer 来轻松地在 React 前端渲染内容。

编号

数字字段显示一个可用于任何类型数字的字段:整数、小数和浮点数。

🌐 The Number field displays a field for any kind of number: integer, decimal and float.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 写下数字字段的名称。 || 数字格式 | 在 整数大整数小数浮点数 之间选择。 |

日期

日期字段可以显示日期(年、月、日)、时间(时、分、秒)或日期时间(年、月、日、时、分、秒)选择器。

🌐 The Date field can display a date (year, month, day), time (hour, minute, second) or datetime (year, month, day, hour, minute, and second) picker.

| 设置名称 | 说明 ||------------|---------------------------------------------------------|| 名称 | 填写日期字段的名称。 || 类型 | 在 datedatetimetime 之间选择 |

密码

密码字段显示已加密的密码字段。

🌐 The Password field displays a password field that is encrypted.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 写下密码字段的名称。 |

媒体

媒体字段允许从应用媒体库中上传的媒体文件中选择一个或多个媒体文件(例如图片、视频)。

🌐 The Media field allows to choose one or more media files (e.g. image, video) from those uploaded in the Media Library of the application.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 撰写媒体字段的名称。 || 类型 | 在 多媒体(允许上传多个媒体)和 单一媒体(只允许上传一个媒体)之间选择。 |

关系

Relation 字段允许与另一个内容类型建立关系,该内容类型必须是集合类型。

🌐 The Relation field allows to establish a relation with another content-type, that must be a collection type.

有 6 种不同类型的关系:

🌐 There are 6 different types of relations:

  • 一种方式:内容类型A 有一个 内容类型B
  • 一对一:内容类型 A 有并属于一个 内容类型 B
  • 一对多:内容类型 A 属于多个 内容类型 B
  • 多对一:内容类型 B 拥有多个 内容类型 A
  • 多对多:内容类型 A 拥有并属于多个 内容类型 B
  • 多种方式:内容类型 A 有多种 内容类型 B
Multi relations and single relations

至少有一方可以引用多个条目的关系称为多重关系。在内容类型构建器中,这包括一对多、多对一、多对多和多向关系。这些关系在内容管理器中显示为多选字段,并且从 REST、GraphQL 和文档服务 API 返回数组;而单一关系(一向和一对一关系)返回单个关联条目(有关更多信息,请参见 使用 API 请求管理关系)。

🌐 Relations where at least one side can reference several entries are called multi relations. In the Content-type Builder, this includes one-to-many, many-to-one, many-to-many, and many-way relations. These relations appear as multi-select fields in the Content Manager and return arrays from the REST, GraphQL, and Document Service APIs; while single relations (one-way and one-to-one relations) return a single linked entry (see Managing relations with API requests for more information).

配置关系字段的基本设置包括选择应与哪个现有内容类型建立关系以及关系的类型。关系字段的编辑窗口显示两个灰色框,每个框代表一个相关内容类型。在灰色框之间显示所有可能的关系类型。

🌐 Configuring the basic settings of the Relation field consists in choosing with which existing content-type the relation should be established and the kind of relation. The edition window of the Relation field displays 2 grey boxes, each representing one of the content-types in relation. Between the grey boxes are displayed all possible relation types.

  1. 点击第二个灰色框以定义内容类型 B。它必须是已创建的集合类型。
  2. 单击代表要在内容类型之间建立的关系的图标。
  3. 选择内容类型 A 的字段名称,即将在内容类型 A 中用于该字段的名称。
  4. (如果关系类型禁用,则可选) 选择内容类型 B 的 字段名称
Modeling nested page hierarchies

要对可导航的页面树进行建模:

🌐 To model a navigable tree of pages:

  1. 添加一个 Page 集合类型,并包含一个“Slug”(UID)字段,以及一个可选的“Order”(整数)字段来控制同级排序。
  2. PagePage 创建一个关联字段,并选择 多对一,这样每个页面都可以设置它的“父页面”。Strapi 会自动提供反向的“子页面”关联。
  3. 在读取数据时,递归地填充 children 以加载树。保持递归深度较小以避免响应过大。
示例
Populate nested children for a page tree
{
populate: {
children: {
fields: ['title', 'slug'],
populate: {
children: {
fields: ['title', 'slug'],
},
},
},
},
}

相同的填充模式适用于 GraphQL 或文档服务 API(参见 理解填充指南)。

🌐 The same populate pattern works with GraphQL or the Document Service API (see Understanding populate guide).

布尔

布尔字段显示一个切换按钮来管理布尔值(例如是或否、1 或 0、True 或 False)。

🌐 The Boolean field displays a toggle button to manage boolean values (e.g. Yes or No, 1 or 0, True or False).

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 填写布尔字段的名称。 |

JSON

JSON 字段允许以 JSON 格式配置数据,以存储 JSON 对象或数组。

🌐 The JSON field allows to configure data in a JSON format, to store JSON objects or arrays.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 写下 JSON 字段的名称 |

电子邮件

电子邮件字段显示带有格式验证的电子邮件地址字段,以确保电子邮件地址有效。

🌐 The Email field displays an email address field with format validation to ensure the email address is valid.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 填写电子邮件字段的名称。 |

密码

密码字段显示已加密的密码字段。

🌐 The Password field displays a password field that is encrypted.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 写下密码字段的名称。 |

枚举

枚举字段允许配置下拉列表中显示的值列表。

🌐 The Enumeration field allows to configure a list of values displayed in a drop-down list.

| 设置名称 | 说明 ||---------------|-----------------------------------------------------------------|| 名称 | 写下枚举字段的名称。 || 值 | 写下枚举的值,每行一个。 |

Caution

枚举值应始终在任何数字前有一个字母字符,否则在安装 GraphQL 插件时可能会导致服务器崩溃而不另行通知。

🌐 Enumeration values should always have an alphabetical character preceding any number as it could otherwise cause the server to crash without notice when the GraphQL plugin is installed.

UID

UID 字段显示设置唯一标识符的字段,可以选择基于相同内容类型的现有其他字段。

🌐 The UID field displays a field that sets a unique identifier, optionally based on an existing other field from the same content-type.

| 设置名称 | 说明 ||----------------|-----------------------------------------------------------------|| 名称 | 输入 UID 字段的名称。名称中不得包含特殊字符或空格。 || 附加字段 | 选择要附加到 UID 字段的现有字段。选择 表示不附加任何特定字段。 |

Tip

UID 字段可用于根据 Attached 字段创建 slug。

🌐 The UID field can be used to create a slug based on the Attached field.

富文本(Markdown)

富文本(Markdown)字段显示一个带有基本格式选项的编辑器,用于管理以Markdown编写的富文本。此字段可用于较长的书面内容。

🌐 The Rich Text (Markdown) field displays an editor with basic formatting options to manage rich text written in Markdown. This field can be used for long written content.

| 设置名称 | 使用说明 ||--------------|---------------------------------------------------|| 名称 | 写入富文本(Markdown)字段的名称。 |

组件

组件是多个字段的组合。组件允许创建可重用的字段集合,这些集合可以快速添加到内容类型、动态区域,也可以嵌套到其他组件中。

🌐 Components are a combination of several fields. Components allow to create reusable sets of fields, that can be quickly added to content-types, dynamic zones but also nested into other components.

通过内容类型生成器配置组件时,可以:

🌐 When configuring a component through the Content-type Builder, it is possible to either:

  • 通过点击 创建新组件 来创建一个新组件(参见 创建新组件),
  • 或者点击使用现有组件来使用已有的组件。

| 设置名称 | 说明 ||--------------------|-----------------------------------------------------------------|| 名称 | 为内容类型写入组件名称。 || 选择组件 | 仅在使用现有组件时 - 从下拉列表中选择一个现有组件。 || 类型 | 在可重复组件单组件之间选择:可重复组件允许为内容类型多次使用该组件,单组件限制该组件仅可使用一次。 |

动态区域

动态区域是可以添加到内容类型中的组件组合。它们允许灵活的内容结构,因为一旦进入内容管理器,管理员可以根据需要选择如何组合和重新排列动态区域的组件。

🌐 Dynamic zones are a combination of components that can be added to content-types. They allow a flexible content structure as once in the Content Manager, administrators have the choice of composing and rearranging the components of the dynamic zone how they want.

| 设置名称 | 指令 ||--------------------|-----------------------------------------------------------------|| 名称 | 为内容类型写入动态区域的名称。 |

在配置动态区域的设置之后,其组件也必须进行配置。可以选择现有组件或创建一个新组件。

🌐 After configuring the settings of the dynamic zone, its components must be configured as well. It is possible to either choose an existing component or create a new one.

Caution

使用动态区域时,不同组件不能具有不同类型(或枚举字段、不同值)的相同字段名称。

🌐 When using dynamic zones, different components cannot have the same field name with different types (or with enumeration fields, different values).

自定义字段

🌐 Custom fields

自定义字段 是通过向内容类型或组件添加新类型字段来扩展 Strapi 功能的一种方式。安装后(参见 Marketplace 文档),在为内容类型选择字段时,自定义字段会列在 自定义 选项卡中。

每种自定义字段类型都可以有基本和高级设置。 Marketplace 列出可用的自定义字段,并为每个自定义字段提供专门的文档,包括具体设置。

删除内容类型

🌐 Deleting content-types

内容类型和组件可以通过内容类型构建器删除。删除内容类型会自动删除内容管理器中基于该内容类型的所有条目。组件的删除也是如此,它会自动从使用该组件的所有内容类型或条目中删除。

🌐 Content types and components can be deleted through the Content-type Builder. Deleting a content-type automatically deletes all entries from the Content Manager that were based on that content-type. The same goes for the deletion of a component, which is automatically deleted from every content-type or entry where it was used.

  1. 内容类型构建器子导航中,点击要删除的内容类型或组件的名称。
  2. 在所选内容类型或组件的编辑界面中,点击内容类型或组件名称右侧的 编辑按钮。
  3. 在编辑窗口中,点击 删除 按钮。
  4. 在确认窗口中,确认删除。
  5. 在内容类型构建器子导航中点击 保存 按钮。
Caution

删除内容类型只会删除通过内容类型构建器创建的内容,以及由此从你的 Strapi 应用的管理面板中可访问的内容。然而,基于该内容类型创建的所有数据仍会保留在数据库中。有关更多信息,请参阅相关 GitHub issue

Deletion of content type in Content-type BuilderDeletion of content type in Content-type Builder