Content Models map your themes content to a structured schema. Content models are defined in the stackbit.yaml inside the models key.

Example

Take the following site structure

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

The following stackbit.yaml would define 2 content models. 1 page model and 1 data model. Inside each are field models.

# stackbit.yaml

stackbitVersion: ~0.2.0
ssgName: custom
pagesDir: content
dataDir: data
...
models: # top level models key
  article: # a content 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 content model
      - type: string
        name: title
        label: Title
  config: # a content 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

Content Model Types

Content models must be one of the following types.

Page Models

A set of settings and fields defining the content structure of a specific page type rendered using a specific layout. For example, the "home" page model might define the content structure of a site's home page with all its sections. While the "article" page model could define the content structure of a blog post.

Data Models

A set of settings and fields defining the content structure of a data source other than site pages. For example, "header" and "footer" data models might define the content structure of a site's header.yml and footer.json data files.

Field Models

Field models are nested inside Page, Data and Object models and define individual fields.

Object Models

A model that defines content structure of an arbitrary object. This model might be reused by being referenced by another object model, data model or page model. For example, a site's home page might have multiple sections, where the content model of each section is defined by a separate Object Model. Another example is an object model defining commonly used UI components such as an action button with predefined properties (label, url, color, etc.).

Common Content Model Fields

type

The type of the model.

  • Example value: page
  • Allowed values: page, data, object
  • Required: true

label

A short, descriptive name for the page model. For example if you were creating a page model for blog content you might use the label "Blog" but you could also use "Article". The label is often displayed in various CMS when viewing the lists of folders or "Content Types".

  • Example value: "Blog Post"
  • Allowed values: string
  • Required: true

description

Description of the model. In some CMS, the description is shown besides models in model lists.

  • Example value: "Blog Posts"
  • Allowed values: string
  • Required: true

fields

The field models attached to the content model.

  • Example value: "Blog Posts"
  • Allowed values: List of Field Models (list of objects)
  • Required: true

Content Models Naming Rules

  • Must start with and end with a lower case letter
  • Can contain only lower case alphanumeric characters and an underscore _