collections
accepts a list of collection objects, each with the following options
Name 17376_d47ba4-20> |
Type 17376_071ee6-f6> |
Default 17376_6ef048-77> |
Description 17376_714adf-8b> |
---|---|---|---|
name 17376_5c5a08-a1> |
string 17376_8ae0dd-c2> | 17376_6addb1-e8> |
Unique identifier for the collection, used as the key when referenced in other contexts (like the relation widget) 17376_59fb84-d5> |
identifier_field 17376_694c4a-b8> |
string 17376_257928-af> |
|
Optional. See identifier field below 17376_cccfe9-f3> |
label 17376_bd3fd3-36> |
string 17376_a8acf9-62> |
|
Optional. Label for the collection in the editor UI 17376_94bd93-17> |
label_singular 17376_f23def-29> |
string 17376_cdba31-b3> |
|
Optional. Singular label for certain elements in the editor 17376_ffeaa2-bd> |
icon 17376_0ed531-62> |
string 17376_b45712-9b> | 17376_f941cf-d1> |
Optional. Unique name of icon to use in main menu. See custom icons 17376_e57db9-7d> |
description 17376_9084ae-b4> |
string 17376_642307-3e> | 17376_7cbda6-96> |
Optional. Text displayed below the label when viewing a collection 17376_5dbff0-57> |
files or folder 17376_43067b-3f> | 17376_cf8ee6-68> | 17376_72268a-c1> |
Requires one of these: Specifies the collection type and location; details in collection types 17376_28afe6-a1> |
filter 17376_4507f7-01> |
FilterRule | 17376_bc507d-ab> |
Optional. Field and file filter for Folder Collections. See filtered folder collections 17376_5fd9f6-b0> |
create 17376_2f3945-27> |
boolean 17376_d6c983-b6> |
|
Optional. For Folder Collections only |
publish 17376_f456a9-7c> |
boolean 17376_971631-d4> |
|
Optional For |
hide 17376_495152-0b> |
boolean 17376_86a153-6f> |
|
Optional. |
delete 17376_823fa9-1a> |
boolean 17376_0d0eff-67> |
|
Optional. |
extension 17376_251fed-37> |
string 17376_a2274e-54> | 17376_9990b0-91> |
Optional. See extension and format below 17376_cbc668-84> |
format 17376_2ab615-62> |
‘yaml’ | 17376_58b6b7-8e> |
Optional. See extension and format below 17376_777991-74> |
frontmatter_delimiter 17376_0e1e7f-9b> |
string | 17376_31f09f-ab> |
Optional. See frontmatter delimiter below 17376_4f3ee7-2a> |
slug 17376_bb742e-22> |
string 17376_3bb46e-50> | 17376_96b9b0-da> |
Optional. See slug below 17376_7881cb-00> |
fields (required) 17376_5bc717-1f> |
Field 17376_7433b9-9b> | 17376_479f36-05> |
Optional. See fields below. Ignored if Files Collection 17376_fda0f2-d4> |
editor 17376_5f7e49-59> |
EditorConfig 17376_0a7742-98> | 17376_a0a4f0-0a> |
Optional. See editor below 17376_087448-63> |
summary 17376_a2f2b9-e9> |
string 17376_01bf32-f3> | 17376_be72b9-60> |
Optional. See summary below 17376_b5e66b-19> |
summary_fields 17376_7b55b9-2c> |
list of strings 17376_0f7153-5b> |
[‘summary’] 17376_ed132a-97> |
Optional. A list of fields to show in the table view 17376_c9d3cb-6d> |
sortable_fields 17376_6b7a60-77> |
SortableFields 17376_f613c4-c5> | 17376_b5c117-78> |
Optional. See sortable fields below 17376_4d9296-0d> |
view_filters 17376_0b4a05-23> |
ViewFilter 17376_b05b1c-0f> | 17376_7e377f-76> |
Optional. See view filters below 17376_e2a077-e4> |
view_groups 17376_fadf35-99> |
ViewGroup 17376_a006b2-ab> | 17376_e6161f-43> |
Optional. See view groups below 17376_300ec0-a7> |
Identifier Field
Static CMS expects every entry to provide a field named "title"
that serves as an identifier for the entry. The identifier field serves as an entry’s title when viewing a list of entries, and is used in slug creation. If you would like to use a field other than "title"
as the identifier, you can set identifier_field
to the name of the other field.
collections:
- name: posts
identifier_field: name
collections: [
{
name: 'posts',
identifier_field: 'name',
},
],
Extension and Format
These settings determine how collection files are parsed and saved. Both are optional—Static CMS will attempt to infer your settings based on existing items in the collection. If your collection is empty, or you’d like more control, you can set these fields explicitly.
extension
determines the file extension searched for when finding existing entries in a folder collection and it determines the file extension used to save new collection items. It accepts the following values: yml
, yaml
, json
, md
, markdown
, mdx
, html
.
You may also specify a custom extension
not included in the list above, as long as the collection files can be parsed and saved in one of the supported formats below.
format
determines how collection files are parsed and saved. It will be inferred if the extension
field or existing collection file extensions match one of the supported extensions above. It accepts the following values:
yml
oryaml
: parses and saves files as YAML-formatted data files; saves withyml
extension by defaultjson
: parses and saves files as JSON-formatted data files; saves withjson
extension by defaulttoml
: parses and saves files as TOML-formatted data files; saves withtoml
extension by defaultfrontmatter
: parses files and saves files with data frontmatter followed by an unparsed body text (edited using abody
field); saves withmd
extension by default; default for collections that cannot be inferred. Collections withfrontmatter
format (either inferred or explicitly set) can parse files with frontmatter in YAML or JSON format. However, they will be saved with YAML frontmatter.yaml-frontmatter
: same as thefrontmatter
format above, except frontmatter will be both parsed and saved only as YAML, followed by unparsed body text. The default delimiter for this option is---
.json-frontmatter
: same as thefrontmatter
format above, except frontmatter will be both parsed and saved as JSON, followed by unparsed body text. The default delimiter for this option is{
}
.toml-frontmatter
: same as thefrontmatter
format above, except frontmatter will be both parsed and saved only as TOML, followed by unparsed body text. The default delimiter for this option is+++
.
Frontmatter Delimiter
If you have an explicit frontmatter format declared, the frontmatter_delimiter
option allows you to specify a custom delimiter like ~~~
. If you need different beginning and ending delimiters, you can use an array like ["(", ")"]
.
Slug
For folder collections where users can create new items, the slug
option specifies a template for generating new filenames based on a file’s creation date and title
field. (This means that all collections with create: true
must have a title
field (a different field can be used via identifier_field
).
The slug template can also reference a field value by name, eg. {{title}}
. If a field name conflicts with a built in template tag name – for example, if you have a field named slug
, and would like to reference that field via {{slug}}
, you can do so by adding the explicit fields.
prefix, eg. {{fields.slug}}
.
Available Template Tags
- Any field can be referenced by wrapping the field name in double curly braces, eg.
{{author}}
{{slug}}
: a url-safe version of thetitle
field (or identifier field) for the file{{year}}
: 4-digit year of the file creation date{{month}}
: 2-digit month of the file creation date{{day}}
: 2-digit day of the month of the file creation date{{hour}}
: 2-digit hour of the file creation date{{minute}}
: 2-digit minute of the file creation date{{second}}
: 2-digit second of the file creation date
Examples
Basic Example
slug: '{{year}}-{{month}}-{{day}}_{{slug}}'
slug: '{{year}}-{{month}}-{{day}}_{{slug}}',
Field Names
slug: '{{year}}-{{month}}-{{day}}_{{title}}_{{some_other_field}}'
slug: '{{year}}-{{month}}-{{day}}_{{title}}_{{some_other_field}}',
Field Name That Conflicts With Template Tag
slug: '{{year}}-{{month}}-{{day}}_{{fields.slug}}',
slug: '{{year}}-{{month}}-{{day}}_{{fields.slug}}',
Fields
Ignored if Files Collection
The fields
option maps editor UI widgets to field-value pairs in the saved file. The order of the fields in your Static CMS config
file determines their order in the editor UI and in the saved file.
fields
accepts a list of widgets. See widgets for more details.
In files with frontmatter, one field should be named body
. This special field represents the section of the document (usually markdown) that comes after the frontmatter.
fields:
- label: "Title"
name: "title"
widget: "string"
pattern: ['.{20,}', "Must have at least 20 characters"]
- {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
- {label: "Featured Image", name: "thumbnail", widget: "image", required: false}
- {label: "Body", name: "body", widget: "markdown", comment: 'This is a multiline\ncomment' }
fields: [
{ label: 'Title', name: 'title', widget: 'string', pattern: ['.{20,}', 'Must have at least 20 characters'] },
{ label: 'Layout', name: 'layout', widget: 'hidden', default: 'blog' },
{ label: 'Featured Image', name: 'thumbnail', widget: 'image', required: false },
{ label: 'Body', name: 'body', widget: 'markdown', comment: 'This is a multiline\\ncomment' },
],
Editor
The editor
setting changes options for the editor view of a collection or a file inside a files collection. It has the following options:
Name 17376_953cfb-6c> |
Type 17376_f18965-2f> |
Default 17376_6d21f0-85> |
Description 17376_96ddf4-91> |
---|---|---|---|
preview 17376_455726-0b> |
boolean 17376_069707-4e> |
|
Set to |
frame 17376_68772a-9a> |
boolean 17376_92c7d1-f5> |
|
|
size 17376_282cd8-f9> |
‘compact’ |
|
The size of the editor: |
editor:
preview: false
frame: false
editor: {
preview: false,
frame: false,
},
Note: Setting this as a top level configuration will set the default for all collections
Summary
The summary
setting allows the customization of the collection table view. Similar to the slug
field, a string with templates can be used to include values of different fields, e.g. {{title}}
. This option over-rides the default of title
field and identifier_field
.
Available Template Tags
Template tags are the same as those for slug, with the following additions:
{{dirname}}
The path to the file’s parent directory, relative to the collection’sfolder
.{{filename}}
The file name without the extension part.{{extension}}
The file extension.{{commit_date}}
The file commit date on supported backends (git based backends).{{commit_author}}
The file author date on supported backends (git based backends).
summary: 'Version: {{version}} - {{title}}'
summary: 'Version: {{version}} - {{title}}',
Template Transformations
You can apply transformations on fields in a summary string template using filter notation syntax.
Example config:
collections:
- name: 'posts'
label: 'Posts'
folder: '_posts'
summary: "{{title | upper}} - {{date | date('yyyy-MM-dd')}} - {{body | truncate(20, '***')}}"
fields:
- { label: 'Title', name: 'title', widget: 'string' }
- { label: 'Publish Date', name: 'date', widget: 'datetime' }
- { label: 'Body', name: 'body', widget: 'markdown' }
collections: [
{
name: 'posts',
label: 'Posts',
folder: '_posts',
summary: "{{title | upper}} - {{date | date('yyyy-MM-dd')}} - {{body | truncate(20, '***')}}",
fields: [
{ label: 'Title', name: 'title', widget: 'string' },
{ label: 'Publish Date', name: 'date', widget: 'datetime' },
{ label: 'Body', name: 'body', widget: 'markdown' },
],
},
],
The above config will transform the title field to uppercase and format the date field using yyyy-MM-dd
format. Available transformations are:
Name 17376_c1b03f-c2> |
Format 17376_43e969-e5> |
Description 17376_481557-81> |
---|---|---|
upper 17376_28fc99-2f> |
|
Transforms the value to uppercase 17376_cb7e45-6a> |
lower 17376_2d413c-30> |
|
Transforms the value to lowercase 17376_5248e2-c5> |
date 17376_ceed4a-c8> |
|
Formats a date string in the provided format. Accepts date-fns tokens 17376_2faa7d-cf> |
default 17376_8b8692-76> |
|
Provides default value if no field value 17376_6b3a29-93> |
ternary 17376_e75055-41> |
|
If field has value, show |
truncate 17376_94ea3b-fd> |
|
Truncates text to a specified length. An optional replacement string for the omitted text can be provided as a second parameter 17376_9d69f0-61> |
Sortable Fields
The sortable_fields
setting is an optional object with the following options:
Name 17376_a3062c-75> |
Type 17376_96d6a2-c7> |
Default 17376_bc667a-94> |
Description 17376_8e7661-f7> |
---|---|---|---|
fields 17376_fced5f-5e> |
list of string 17376_155460-bc> | 17376_00f64c-a9> |
A list of sort fields to show in the UI 17376_e91b48-7b> |
default 17376_cef689-63> |
SortableFieldsDefault 17376_144634-9a> | 17376_4f6a21-9f> |
Optional. The default field and direction to sort the collection. See Default Sort for details 17376_a602f2-b5> |
Defaults to inferring title
, date
, author
and description
fields and will also show Update On
sort field in git based backends.
When author
field cannot be inferred commit author will be used.
# use dot notation for nested fields
sortable_fields:
fields: ['commit_date', 'title', 'commit_author', 'language.en']
// use dot notation for nested fields
sortable_fields: {
fields: ['commit_date', 'title', 'commit_author', 'language.en'],
},
Default Sort
Name 17376_179422-6e> |
Type 17376_afb343-51> |
Default 17376_b260c2-3a> |
Description 17376_635fed-8f> |
---|---|---|---|
field 17376_8ea1ef-6a> |
string 17376_2ab9a8-e9> | 17376_595a5d-da> |
The field to sort 17376_0fd38a-b1> |
direction 17376_578f9c-d7> |
‘Ascending’ |
|
Optional. The direction to sort 17376_56911c-51> |
# use dot notation for nested fields
sortable_fields:
fields: ['commit_date', 'title', 'commit_author', 'language.en']
default:
field: commit_date
direction: Descending
// use dot notation for nested fields
sortable_fields: {
fields: ['commit_date', 'title', 'commit_author', 'language.en'],
default: {
field: 'commit_date',
direction: 'Descending'
}
},
View Filters
The view_filters
setting is an optional property which takes a list of predefined view filters to show in the UI and an optional default view filter.
view_filters:
default: drafts
filters:
- name: alice-and-bob
label: "Alice's and Bob's Posts"
field: author
pattern: 'Alice|Bob'
- name: posts-2020
label: 'Posts published in 2020'
field: date
pattern: '2020'
- name: drafts
label: Drafts
field: draft
pattern: true
view_filters: {
default: 'drafts',
filters: [
{
name: 'alice-and-bob',
label: "Alice's and Bob's Posts",
field: 'author',
pattern: 'Alice|Bob',
},
{
name: 'posts-2020',
label: 'Posts published in 2020',
field: 'date',
pattern: '2020',
},
{
name: 'drafts',
label: 'Drafts',
field: 'draft',
pattern: true,
},
],
},
View Groups
The view_groups
setting is an optional property which takes a list of predefined view groups to show in the UI and an optional default view group.
view_groups:
default: by-year
groups:
- name: by-year
label: Year
field: date
# groups items based on the value matched by the pattern
pattern: \d{4}
- name: drafts
label: Drafts
field: draft
view_groups: {
default: by-year
groups: [
{
name: 'by-year',
label: 'Year',
field: 'date',
pattern: '\\d{4}',
},
{
name: 'drafts',
label: 'Drafts',
field: 'draft',
},
],
},
Media Library
The media_library
settings allows customization of the media library at the collection level.
Options
Name 17376_fc0131-9a> |
Type 17376_bdfd64-08> |
Default 17376_0c2b7b-2e> |
Description 17376_32f328-e1> |
---|---|---|---|
max_file_size 17376_6325bc-c8> |
number 17376_4dbdd5-1b> |
|
Optional. The max size, in bytes, of files that can be uploaded to the media library 17376_7f0072-3c> |
folder_support 17376_b2871e-bc> |
boolean 17376_89957c-5f> |
|
Optional. Enables directory navigation and folder creation in your media library 17376_d63564-5e> |
Example
media_library:
max_file_size: 512000
folder_support: true
{
media_library: {
max_file_size: 512000,
folder_support: true
}
}