Search code examples
netlify-cms

How to get multiple collections working within Netlify-CMS?


I'm running a Gridsome project where I have integrated Netlify-CMS. This is what my config.yml file looks like:

backend:
  name: github
  branch: master # Branch to update (optional; defaults to master)
  repo: user/repo
media_folder: "images/uploads"
public_folder: "/images/uploads"
collections:
  - name: "blog" # Used in routes, e.g., /admin/collections/blog
    label: "Blog" # Used in the UI
    folder: "blog" # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
    fields: # The fields for each document, usually in front matter
      - {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Featured Image", name: "thumbnail", widget: "image"}
      - {label: "Body", name: "body", widget: "markdown"}
  - name: "projects" # Used in routes, e.g., /admin/collections/blog
    label: "Projects" # Used in the UI
    folder: "projects" # The path to the folder where the documents are stored
    create: true # Allow users to create new documents in this collection
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}" # Filename template, e.g., YYYY-MM-DD-title.md
    fields: # The fields for each document, usually in front matter
      - {label: "Layout", name: "layout", widget: "hidden", default: "blog"}
      - {label: "Customer", name: "customer", widget: "string"}
      - {label: "Activity", name: "activity", widget: "string"}
      - {label: "Date", name: "date", widget: "datetime"}
      - {label: "Link", name: "link", widget: "string"}
      - {label: "Featured Image", name: "thumbnail", widget: "image"}
      - {label: "Body", name: "body", widget: "markdown"}

I'm able to see both Blog and Projects in the admin interface, however, when I click on the Project collections it doesn't show my existing .md file within the specified folder. At the same time, when I try to create a new project, this doesn't get added and no error message is displayed.

Everything works like a charm with the Blog collection.

This is what the project directory looks like:

project directory


Solution

  • There's no field that can serve as an identifier. Right now you either have to have a field named "title" or set "identifier_field" to the name of a field that you'd like to use instead. The value of the field should be unique to the entry, so I'm guessing adding a "title" to each project is probably a good move anyway.

    There should be an error for this, if you could open a bug in GitHub for that we can look into it.