Choose your preferred SSG:
Choose your preferred SSG:

Keeping content consistent across files in a collection

When you edit a file in a collection with a schema defined, the front matter or data is updated to match the configured schema. This allows you to keep your files consistent across a collection as they are edited by adding, removing, or reordering inputs in the schema file.

Follow these steps to create and configure a schema for your collection.

Here’s an example schema file and the required configuration for a posts collection:

        path: schemas/

Existing files are not processed before being loaded into the editor if a schema is not configured on the collection.

Since multiple schemas can be defined, the _schema field inside the file being edited is used to find the correct one. The _schema field is automatically added when creating files for a collection with schemas within CloudCannon.

The default schema is used if _schema does not exist. You can change the field from _schema with the schema_key option when defining your collections.


In this example, we have the schema defined above for the posts collection, and we have the following post that was created when the schema had different fields:

_schema: default
title: My post
category: news
This is the content of my post!

After editing this post there are these changes:

  1. category was removed
  2. author and image were added
  3. All inputs were reordered to match the schema
_schema: default
title: My updated post
author: /authors/jane
image: /images/posts/header.png
This is the updated content of my post!

You can control whether inputs are reordered, removed and/or hidden with the reorder_inputs, remove_empty_inputs and hide_extra_inputs schema options.

Was this article helpful? or Suggest an improvement >

Related articles