Handling Contentful Presets

Presets in Contentful are unique because of the way references work.

In Contentful, all relationships among objects are references — you can't embed entries inside another entry. By default, Stackbit uses existing references when creating new content from a preset.

Consider a scenario in which a page model has two fields — components and author — both of which hold references to other entries in the CMS.

If you then create a new page from a preset, Stackbit will use the existing components and author entries. The only new content created will be the page entry.

You can override this behavior using the presetReferenceBehavior setting in your configuration file. See below for examples.

Visual representation of presetReferenceBehavior setting
Visual representation of presetReferenceBehavior setting
Note that preset configuration changes only apply to newly-created presets. This is because preset configurations are stored as files and Stackbit will not adjust existing files in your repository.

Duplicating References

If you'd prefer the Stackbit duplicate references by default rather than using existing references, you can set that behavior in your configuration file.

  • 1
  • 2
  • 3
  • 4
export default {
  presetReferenceBehavior: 'duplicateContents',
  // ...
}

Adding Models as Exceptions

There will likely be exceptions to that rule. Again using the example above, you may want buttons to be duplicated, but author references to be copied.

Specifying Exceptions to copyReference

In that case, we can leave the default presetReferenceBehavior set to copyReference and set the models which should duplicate the content instead (button).

  • 1
  • 2
  • 3
  • 4
export default {
  duplicatableModels: ['button'],
  // ...
}
Visual representation of duplicatableModels setting
Visual representation of duplicatableModels setting

Specifying Exceptions to duplicateContents

The option changes if you've overridden the default behavior. In that case, you'd use nonDuplicatableModels:

  • 1
  • 2
  • 3
  • 4
  • 5
export default {
  presetReferenceBehavior: 'duplicateContents',
  nonDuplicatableModels: ['author'],
  // ...
}
Visual representation of nonDuplicatableModels setting
Visual representation of nonDuplicatableModels setting