Docs (Public)

Content Models map your theme's content to a structured schema. Content models are defined in the stackbit.yaml under the models key. The two primary types of content models that you will work with are Page Models, representing page based content (e.g. .md files), and Data Models, representing file-based structured data (e.g. YAML, TOML or JSON files).

Example

Take the following site structure:

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

The stackbit.yaml would define 2 content models. 1 page model representing the posts and 1 data model representing the config. Inside each of these content 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 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 Models Naming Rules

As shown above, content models are named as keys within the YAML file and must adhere to the following rules:

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

    Content Model Types

Content models must be one of the following types:

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 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.

Field Models

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

Object Models

A model that defines the content structure of an arbitrary object that can 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 the 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 beside models in model lists.

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

fields

The fields that that make up the data within the content model.

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