Nested Collections (beta)
This feature is in beta, please use with discretion.
A nested collection allows a folder collection to show a nested structure of entries and edit the locations of the entries.
It is useful when you have a complex folder structure and may not want to create separate collections for every directory.
To enable it:
Add a
nestedobject to the collection config. Then configure it with these properties:depth: max depth to show in the collection treesummary: optional summary for a tree node, defaults to the inferred title fieldsubfolders: (default: true) if set to false, you don’t need to have md files in subfolders. 3.6
Add a
metaobject with apathproperty. It allows editing the path of entries.pathaccepts these properties:labelandwidget(required): the label and widget of the path field in the editor, usuallywidget: stringindex_file: the name of the file, without the extension, that entries are saved as inside their path. Withindex_file: '_index', an entry with the pathposts/hello-worldis saved ascontent/pages/posts/hello-world/_index.md. This fitssubfolders: true.Without
index_file, new entries are saved in their path as a file named after theirtitlefield, and existing entries keep their file name. An entry titled “Hello World” with the pathpostsis saved ascontent/pages/posts/hello-world.md. This fitssubfolders: false. 3.13
Moving an existing entry will move the entire subtree of the entry to the new location. With
subfolders: false, only the entry’s own file moves.
Example configuration:
collections:
- name: pages
label: Pages
label_singular: Page
folder: content/pages
create: true
fields: [
{name: title, label: Title, widget: string},
{name: body, label: Body, widget: markdown},
]
# Add nested and meta objects
nested:
depth: 100
summary: '{{title}}'
subfolders: true
meta: { path: { widget: string, label: 'Path', index_file: '_index' } }
Directory structure
Nested collections with subfolders: true (default) expect the following directory structure:
content
└── pages
├── _index.md
├── authors
│ ├── _index.md
│ └── author-1
│ └── _index.md
└── posts
├── _index.md
└── hello-world
└── _index.md
With subfolders: false, you can do it like this:
content
└── pages
├── _index.md
├── authors
│ ├── _index.md
│ └── author-1.md
└── posts
├── _index.md
└── hello-world.md