Data models describe data files formatted using either JSON, TOML or YAML. Common examples might be a data/footer.json that contains the site's footer configuration or config.toml that contains site's configuration options.
Data Models share the common model properties.
In addition to common properties, data models have the following properties with similar behavior as in Page Models:
file - path to the data file relative to the dataDir folder. Cannot be combined with folder, match and exclude matching options.folder - path to the folder, relative to the dataDir folder, containing the data files. The default value for folder is an empty string, matching all data files in dataDir. This value can be combined with the match and exclude options to fine tune the files to match.match - specifies which files to match, defaults to **/* which matches all files. The match is executed in the context of the folder.exclude - specifies which files to exclude from the match, defaults to unset value which does not exclude anything. The exclude is executed in the context of the folder.Take the following site structure
.
├── content
│ └── posts
│ ├── post1.md
│ └── post2.md
├── data
│ └── footer.json
└── stackbit.yaml
The data in the data/footer.json file
{
"features": [
{
"title": "Free Consultation",
"description": "New clients recieve an obligation free consultation.",
"image": "images/features/noun_branding_1885335.svg"
},
{
"title": "Certified Accountants",
"description": "All members of our team are certified accountants.",
"image": "images/features/noun_The Process_1885341.svg"
},
{
"title": "Tax Compliance",
"description": "We stay up to date on the latest changes to the tax code.",
"image": "images/features/noun_3d modeling_1885342.svg"
}
]
}
Would map to the following data model in the stackbit.yaml:
stackbitVersion: ~0.2.0
ssgName: custom
pagesDir: content
dataDir: data
...
models:
features:
type: data
label: Features
file: footer.json # path is relative to the `dataDir`
fields:
- type: list
name: features
items:
type: object
label: Feature
labelField: title
fields:
- type: string
name: title
label: Title
- type: string
name: description
label: Description
- type: image
name: image
label: Icon
If you have data files in multiple folders and or data/config files in the root you can set dataDir: "", which will scan the entire project for data files.
.
├── content
│ └── posts
│ ├── post1.md
│ └── post2.md
├── data
│ └── footer.json
├── stackbit.yaml
└── config.yaml