Default fields
Instead of defining fields each time you create a page, post, or document, you can set defaults in your _config.yml theme file. In most cases, it’ll be handy to set at least the default layout.
The defaults key in your _config.yml file is a list of different defaults. Each list item has two objects: scope and values.
scopeis how you choose which collection and files you’re defining defaults on.valuesis where you define your default fields as key/value pairs. Keys can be nested and their values are optional.
For example:
defaults:
-
scope:
path: ""
type: "posts"
values:
layout: "default"
author: "Ethan"
-
scope:
path: ""
type: "pages"
values:
layout: "page"
-
scope:
path: "projects"
type: "pages"
values:
colors: ["red", "green", "blue"]
layout: "project"
-
scope:
path: ""
type: "locations"
values:
map:
latitude:
longitude: In this case, we’re:
- Setting the default
layoutandauthorfor all posts. - Setting the default
layoutfor all pages. - Overriding the previous default
layoutfor all pages in theprojects/path, and setting a defaultcolorsList field with the valuesred,green,blue. - Defining fields for
map.latitudeandmap.longitudefor all documents in thelocationscollection. Using blank values, these fields will show up to content editors but remain optional.
Note that type can be posts, pages or any other collection name (e.g. people).