Docs (Public)

Data models are derived from data files. Data files can be JSON/TOML/YAML formats. For example, data/authors.json or config.toml.

Data models have access to all common content model fields.

Data models are also used to model "config" files that are typical of static site generators.

Example

Take the following site structure

.
├── content
│   └── posts
│       ├── post1.md
│       ├── post2.md
├── data
│   └── footer.json
└── stackbit.yaml

The data model in the stackbit.yaml

# 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

The data in the JSON file

// data/footer.json

{
  "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"
    }
  ]
}

Data in Multiple Folders

If you have data files in multiple folders and or data/config files in the root you can set dataDir: "" this will scan the entire project for data files.

.
├── content
│   └── posts
│       ├── post1.md
│       ├── post2.md
├── data
│   └── footer.json
├── stackbit.yaml
└── config.yaml
# stackbit.yaml

stackbitVersion: ~0.2.0
ssgName: custom
pagesDir: content
dataDir: ""
...
models:
  config:
    type: data
    label: Config
    file: _config.yml # relative to `dataDir`
  author:
    type: data
    file: data/footer.json # relative to `dataDir`
    label: Footer