Choose your preferred SSG:
Choose your preferred SSG:

Creating collection schemas

Collection schemas are used to:

To create a schema:

  1. Create a file with the contents and type you need (e.g. schemas/post.md)
  2. Configure a collection in your global configuration file to use that file
schemas/post.md
---
title:
author:
image:
---
cloudcannon.config.yml
collections_config:
  posts:
    schemas:
      default:
        path: schemas/post.md

You can define multiple schemas for a collection, each with their own file and options:

cloudcannon.config.yml
collections_config:
  posts:
    schemas:
      default:
        path: schemas/posts/default.md
      news:
        path: schemas/posts/news.md
        name: Newsletter Entry

Options

Each entry in schemas has the following options available:

hide_extra_inputs - Boolean

Sets the behavior when editing existing files with inputs not present in the schema with remove_extra_inputs set to false. Defaults to false. Has no effect if remove_extra_inputs is true.

If true, non-schema inputs are hidden in the Data Editor.

If false, non-schema inputs are visible in the Data Editor.

icon - String

Displayed in the add menu when creating new files, also used as the icon for collection files if no other preview is found. Must be a Material Icon name. Defaults to notes.

image_key - String

Defines a front matter field to use when displaying an image on an item. Should match a front matter field in the file. Defaults to using the containing collection image_key.

image_size - String

Sets how images are displayed in the list. Must be unset, cover or contain. Defaults to using the containing collection image_size.

name - String

Displayed in the add menu when creating new files. Defaults to a formatted version of the key.

new_preview_url - String

Preview your unbuilt pages (e.g. drafts) to another page’s output URL. The Visual Editor will load that set preview URL and use the Data Bindings and Previews to render your new page without saving.

For example new_preview_url: /about/ will load the /about/ URL on new or unbuilt pages in the Visual Editor.

path - String

The path to the schema file. Relative to the root folder of the site. Required.

reorder_inputs - Boolean

Controls whether or not inputs are sorted to match the schema when editing existing files. Defaults to true.

Non-schema inputs are ordered after schema inputs if not removed with remove_extra_inputs.

remove_empty_inputs - Boolean

Sets the behavior when saving files with empty inputs. Defaults to false.

If true, empty inputs are removed before persisting the data to the source file.

If false, empty inputs are persisted in the source file.

Removed inputs are available for editing again provided they are in the matching schema file. Inputs are considered empty if the value is null, undefined or ''.

remove_extra_inputs - Boolean

Sets the behavior when editing existing files with inputs not present in the schema. Defaults to true.

If true, non-schema inputs are removed before the editor loads, and subsequently removed from the source file if saved.

If false, non-schema inputs are either hidden or visible in the editor depending on hide_extra_inputs, but still kept in the source file on save.

If any inputs conflict with schema (e.g. a file’s title is a string and the schema’s title is an object), the schema version takes priority.

subtext_key - String

Defines a front matter field to use when displaying subtext on an item. Should match a front matter field in the file. Defaults to using the containing collection subtext_key.

text_key - String

Defines a front matter field to use when displaying text on an item. Should match a front matter field in the file. Defaults to using the containing collection text_key.

Was this article helpful? or Suggest an improvement >

Related articles