如何通过Netlify CMS为Hugo Forty主题添加params.tiles.showcase变量
如何通过Netlify CMS管理Hugo Forty主题的Tiles Showcase条目
要让Netlify CMS能管理Hugo Forty主题的params.tiles.showcase条目,你需要在config.yml里新增一个文件类型的集合(因为这是站点级配置,不是单篇内容),而不是用现有的文件夹式集合。具体操作如下:
1. 理解配置对应关系
你的config.toml里的[[params.tiles.showcase]]是数组结构,对应Netlify CMS里的list组件;[params.tiles]是对象结构,对应CMS里的object组件,我们需要把这两个结构映射到CMS的配置里。
2. 修改Netlify CMS的config.yml
在现有的collections数组中,新增一个专门管理站点配置的集合,用来编辑config.toml中的Tiles部分:
collections: - name: "blog" label: "Blog post" folder: "post/" create: true fields: - { label: "Title", name: "title" } - { label: "Publish Date", name: "date", widget: "datetime" } - { label: "Description", name: "description", widget: "markdown", required: false } - { label: "Featured Image", name: "image", widget: "image", required: false } - { label: "Body", name: "body", widget: "markdown", required: false } # 新增:管理Tiles配置的集合 - name: "site-config" label: "Site Configuration" files: - name: "tiles-settings" label: "Tiles Section Settings" file: "config.toml" # 指向你的站点配置文件,根目录直接写这个路径即可 fields: - label: "Tiles Section" name: "params.tiles" widget: "object" fields: - { label: "Enable Tiles Section", name: "enable", widget: "boolean", default: true } - label: "Showcase Items" name: "showcase" widget: "list" # 用list组件实现多条目添加/删除 fields: - { label: "Showcase Title", name: "title", widget: "string", required: true } - { label: "Showcase Subtitle", name: "subtitle", widget: "string", required: false } - { label: "Showcase Image", name: "image", widget: "image", required: true } - { label: "Showcase Link URL", name: "url", widget: "string", required: true }
3. 关键配置说明
file: "config.toml":确保路径和你的站点配置文件位置一致,若配置文件在项目根目录则无需修改。widget: "object":对应Toml里的[params.tiles]对象,把Tiles相关字段打包成一个独立配置区块。widget: "list":对应Toml里的[[params.tiles.showcase]]数组,CMS后台会提供「Add Item」按钮,支持批量添加、编辑或删除showcase条目。- 字段属性:可根据需求设置
required或default值,比如enable默认设为true,和你现有配置保持一致。
4. 使用流程
配置完成后,进入Netlify CMS后台,找到Site Configuration下的Tiles Section Settings,即可:
- 开关Tiles模块的启用状态
- 添加新的showcase条目,填写标题、副标题、图片和链接
- 编辑或删除已有的showcase条目
保存修改后,Netlify CMS会自动将变更提交到你的Git仓库,触发Netlify部署流程,新的Tiles内容就会生效。
内容的提问来源于stack exchange,提问作者Thomas
相关产品推荐
相关产品推荐

