Presets are stored in JSON files in the project's repository by default, but can also be stored in a remote content source with the appropriate configuration. See here for more information about remote presets.
The structure of file-based presets objects and remote presets is different. Both are referenced below.
File-Based Presets API
The default location for preset configuration files is .stackbit/presets
in your site's repository. This can be customized using the presetSources
config property.
Each file in the presets directory must contain two keys, as noted below:
See below for more information.
model
Each preset file may contain one and only one model
property representing the name of the model to which its presets apply.
1
2
3
4
5
6
model
property. This makes for easier navigation among preset files.
presets
Presets are supported for any component that is modeled and used within your site. This includes both pages, as well as components nested to any depth within the page.
Each entry in the presets
contains the configuration for a single preset. The entry has the following properties:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
See below for further nuance within the properties above.
It may also be helpful to refer to the feature guide.
Remote Presets Fields
When using a content source defined with the contentSources
property, presets can be stored in a remote content source by creating a stackbitPreset
model with the fields shown in the table below.
Note the following:
- Netlify Create will use the first
stackbitPreset
model it finds from sources defined incontentSources
, starting from the first element in the array. - File-based presets can not also be used and the
presetSource
property will be ignored. - The data stored in the
data
field includes additional information beyond what you would find in a file-based preset. For example,metadata
is embedded indata
in a remote preset, while it is a sibling todata
in a file-based preset.
Preset Data Attributes
The object contained within the data
property of a particular preset is the data that gets stored in the content source when a component is added using the preset. The properties in this section are reserved and result in specific behavior when creating content from the preset.
See the sections below for more information about these properties.
$$ref
When the field within an object is of type reference
and the preset is configured to refer to an existing document, the $$ref
property provides Netlify Create with the ID value of the existing document in the content source.
This also applies to remote assets, where the value of $$ref
should be the ID of the image in the content source. (This does not apply to assets stored in the repository, where value is the relative local path to the image file.)
Below is an example using file-based presets. Presets stored remotely follow the same concept, but the structure of data
differs slightly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$$type
property instead.
$$type
When the field within an object is of type reference
or model
, and the preset is configured to create a new object in the content source, the $$type
property provides Netlify Create with the ID value of the appropriate model to use when creating the new, referenced document.
This property should be used even when the field can be of only a single model.
Below is an example using file-based presets. Presets stored remotely follow the same concept, but the structure of data
differs slightly.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$$type
does not need to be used when $$ref
is set, as Netlify Create will be able to infer the type from the referenced document.
Handling References in API Sources
When the presets refer to content stored in API-based content sources, there are scenarios in which you may or may not want to duplicate references when creating content from presets. These options are defined in the project configuration.
Note that changes you make to the global configuration of presets only applies to new presets, given that presets are stored as files.