条目蓝图是用于定义您网站区域的标准内容结构。内容结构和条目可以通过不同方式组织,正如我们在此处更详细描述的那样。
entry 类型支持多个条目,当没有其他变体适用时应使用。
handle: Team\Member
type: entry
name: Team Member
fields:
name:
label: First Name
type: text以下属性由条目蓝图支持。
| Property | Description |
|---|---|
| handle | A meaningful and unique code to identify the entry. |
| type | The blueprint type which can be a variant of entry, single, structure or stream. |
| name | The label to display when working with this entry. |
| fields | form fields belonging to the group, see backend form fields. |
| groups | references a group of form fields placing the entry in group mode (see below). |
| structure | structure configuration supplied when using the structure type. |
| drafts | enables drafts for this entry. Default: false |
| softDeletes | enables soft deletion for this entry. Default: true |
| multisite | enables multisite for this entry, sync records between group, locale or all sites. Supported values: true, false, sync, locale, all. Default: false |
| pagefinder | includes blueprint type in the pagefinder form widget, supported values: true, false, item, list or array (see below). Default: true |
| defaultSort | used by the entry and stream types, sets a default sorting column and direction when user preference is not defined. Supports a string or an array with keys column and direction. The direction can be asc for ascending (default) or desc for descending order. |
| customMessages | customize the messages used in the user interface (see below). |
| showExport | displays a toolbar button for exporting records. Default: true. |
| showImport | displays a toolbar button for importing records. Default: true. |
虽然条目类型没有特定的行为,但也存在几种可用于组织内容的变体。以下类型是条目的变体。
single 类型将强制每个节定义只包含一个条目。这对于一次性内容很有用,例如主页或联系我们页面。下面定义了一个 主页 节,其中包含一个欢迎消息 (welcome_message) 文本字段。
handle: Homepage
type: single
name: Homepage Content
fields:
welcome_message:
label: Welcome Message
type: text该structure类型允许多个结构化条目,允许存在父子关系。这对于嵌套内容很有用,例如文档部分。类型为structure的条目是可排序的。可以通过在列表视图中拖动它们来调整其排序顺序。以下定义了一个文档树形部分,其中包含一个文章内容(article_content)Markdown 字段。
handle: Docs\Article
type: structure
name: Documentation Article
fields:
content:
label: Article Content
type: markdown默认情况下,结构支持无限嵌套,但是,您可以使用 structure 属性中的 maxDepth 指定树的最大深度。在下一个示例中,只能有一个顶级和第二级。
# ...
type: structure
structure:
maxDepth: 2
# ...以下值受 structure 属性支持。
| Property | Description |
|---|---|
| maxDepth | Maximum depth for the structure. Default: 0 for unlimited. |
| treeExpanded | if tree nodes should be expanded by default. Default: true |
| showReorder | displays an interface for reordering records. Default: true |
| showSorting | allows sorting records, disables the structure when sorted. Default: true |
stream 类型用于基于时间的条目,这些条目通常按时间顺序排列。这对于发布最新活动很有用,例如博客部分。下面定义了一个 博客 feed 部分,其中包含一个文章内容 (content) 富文本编辑器字段。
handle: Blog\Post
type: stream
name: Blog Post
fields:
content:
label: Post Content
type: richeditordefaultSort 属性用于设置当蓝图记录以列表形式显示时的默认排序列。这将被默认设置为发布日期。
handle: Blog\Post
type: stream
name: Blog Post
defaultSort:
column: title
direction: asc所有条目都可选地支持为一个部分定义多个内容组。例如,一个博客部分可能有一个常规帖子和一个特色帖子,这些是两个条目组。
条目组由区段蓝图文件中的 groups 属性定义,并且可以为每种类型指定不同的 字段。选定的组值在记录上作为 content_group 属性可用。
handle: Blog\Post
type: stream
name: Blog Post
groups:
regular_post:
name: Regular Post
fields:
# ...
featured_post:
name: Featured Post
fields:
# ...It is recommended to use mixin blueprints to group common field definitions.
:::
指定 customMessages 属性以覆盖界面使用的默认消息。这些值可以是纯文本,也可以引用一个本地化字符串。
customMessages:
buttonCreate: Create New Event以下消息可重写为自定义消息。
::: details 查看可用消息列表
| Message | Default Message |
|---|---|
| buttonCreate | Create :name Entry |
| titleIndexList | Manage :name Entries |
| titleCreateForm | Create :name |
| titleUpdateForm | Update :name |
| pagefinderItemType | :name Entry |
| pagefinderListType | All :name Entries |
| ::: |
条目记录在保存之前需要填充 title 和 slug 字段,此外,slug 字段也必须是唯一的。您可以通过在蓝图中覆盖这些字段来修改此功能。可以通过将 validation 属性设置为 false,或者将 hidden 属性设置为 true 并将其从用户界面中隐藏。以下示例将禁用这两个字段的验证并隐藏 slug 字段。
fields:
title:
validation: false
slug:
hidden: true默认情况下,所有条目都包含在 页面查找器 查找值。这可以通过将 页面查找器 设置为 false 禁用。
pagefinder: false您可以限制页面查找器上下文,使其仅允许将页面定位为单个 item (例如,博客文章)或 list 形式的项(例如,所有博客文章),或者当设置为 all 时将同时显示两者。
pagefinder: item
pagefinder: list页面查找器将自动解析 id、code、slug 和 fullslug 属性,并将其用作 页面 URL 参数 中的替代项。您可以使用 pagefinder 属性,以数组形式指定自定义的 替代项,其中包括上述可选的 上下文。
pagefinder:
context: list
replacements: []每个替换键应与一个 URL 参数名称匹配,并使用点表示法路径来指向属性值。以博客文章页面的以下 URL 示例为例。
url = "/blog/post/:author/:category/:slug/:id"以下替换将把 :author 参数设置为相关作者的 slug 属性值,并将 :category 参数设置为第一个相关类别的 slug 属性值。
pagefinder:
replacements:
author: author.slug
category: categories.0.slug全局变量用于定义您网站的全局可用内容。这些字段值常用于CMS 布局并包含设置,例如社交网络链接。
以下定义了一个 页脚配置 全局,包含一个 Facebook 链接 (facebook_link) 文本字段。
handle: Site\Footer
type: global
name: Footer Config
fields:
facebook_link:
label: Facebook Link
type: text以下属性由全局蓝图支持。
| Property | Description |
|---|---|
| handle | A meaningful and unique code to identify the entry. |
| name | The label to display when working with this entry. |
| fields | form fields belonging to the group, see backend form fields. |
| multisite | enables multisite for this entry, supported values: true, false. Default: false |
| formSize | the settings form size, supported values: tiny, small, medium, large, huge, giant, adaptive. Default: huge. |
Mixin 是一组字段,用于在定义内容结构时避免重复。例如,一个 Location 字段可能在多个地方使用,但我们可以使用一个 mixin 定义只定义它一次。
以下定义了一个位置集合,其中包含国家(country_code)和州(state_code)文本字段。
handle: Fields\Location
type: mixin
name: Location
fields:
country_code:
label: Country
type: text
state_code:
label: State
type: text以下属性受 mixin 蓝图支持。
| Property | Description |
|---|---|
| handle | A meaningful and unique code to identify the entry. |
| name | The label to display when working with this entry. |
| fields | form fields belonging to the group, see backend form fields. |
考虑在mixin文件和字段名前加上下划线 (_) 以便蓝图类型易于查找。例如:
_location_fields.yaml
要在您的条目中包含这些字段,就像任何其他表单字段一样,使用 type 为 mixin 并在 source 属性中引用 UUID 或句柄。
_location_fields:
type: mixin
source: Fields\Location请参阅 Mixin 字段 以获取有关使用 mixin 的更多信息。