I’m using NetlifyCMS with my Hugo website. Can you guys help me how can I change/create directory for my posts. Suppose default directory for my posts is “content/post” what if I want to change it to “content/post/dir1”? Or from “content/post/dir1” to “content/post/dir2”?
You can set that on your collection settings. Do note that subfolders are not yet supported, so that only works when another collection isn’t using content/post
. To avoid trouble, it might be better to use content/dir1
and content/dir2
collections:
- label: "Post"
name: "post"
folder: "content/post/dir1"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
I’ve following code in congif.yml
collections:
- name: "post"
label: "Post"
folder: "content/post"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
According to your guide I guess I need to make new collections for each of directory by changing “folder: ‘path’” specifically for each. Right?
That is correct, yes!
but I received this message
Error loading the CMS configuration
Config Errors:
YAMLException: duplicated mapping key at line 92, column -1070:
collections: # A list of collect …
^
Check your config.yml file.
I tried like
First collection`
collections:
- name: "post"
label: "Post"
folder: "content/post"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
2nd collection
collections:
- name: "post"
label: "Post"
folder: "content/post/dir1"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
but found error on login page for duplication
Collections is a yml list, you can add collection entries like this:
collections:
- name: "post1"
label: "Post 1"
folder: "content/post/dir1"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}
- name: "post2"
label: "Post 2"
folder: "content/post/dir2"
create: true
fields:
- {label: "Title", name: "title", widget: "string"}
- {label: "Publish Date", name: "date", widget: "datetime"}