Models map your theme's content to a structured schema. Models are defined in the stackbit.yaml under the models
key. The three primary types of models that you will work with are:
.md
files).Assume a site with the following content structure:
.
├── content
│ └── posts
│ ├── post1.md
│ └── post2.md
├── data
│ └── config.yaml
└── stackbit.yaml
The stackbit.yaml
would define 2 models. 1 page model representing the posts and 1 data model representing the config. Inside each of these models are the corresponding field models.
# stackbit.yaml
stackbitVersion: ~0.2.0
ssgName: custom
pagesDir: content
dataDir: data
...
models: # top level models key
article: # a model called "article"
type: page # this is a page model
label: Article
folder: posts # matches all markdown files in the content folder
fields: # array of field models, must be nested under a model
- type: string
name: title
label: Title
config: # a model called "config"
type: data # this is a data model
label: Config
file: config.yaml # matches a single file
singleInstance: true
fields:
- type: string
name: title
label: Sites Title
- type: image
name: logo
label: Path to Logo Image
As shown above, models are named as keys within the YAML file and must adhere to the following rules:
_
Models must be one of the following types:
page
- this model type represents Page Models. Settings and fields that define the content structure of a specific page type with common front matter fields. For example, the "home" page model might define the content structure of a site's home page, while the "article" page model could define the content structure of blog posts.data
- this model type represents Data Models. Settings and fields that defining the content structure of a data file (e.g. YAML, TOML or JSON). For example, "header" and "footer" data models might define the content structure of a site's header.yml and footer.json data files.