2
votes

I'm a little confused with Netlify's CMS - specifically when it comes to defining a schema via config.yml. I'm using Netlify CMS with a Gatsby static site to allow the end user to update some little bits of dynamic data on the website.

What I'm trying to achieve:

I want a data type on the CMS to allow the user to create new tour dates, with a maximum occupancy and a current occupancy (i.e. how many people are currently booked on said tour).

To achieve this I've currently gone with this config.yml (this config.yml is located in static/admin of my Gatsby project w.r.t the project root):

backend:
  name: git-gateway
  branch: master

publish_mode: editorial_workflow

media_folder: src/images/uploads
public_folder: /uploads

collections:
  - name: "tourInfo"
    label: "Tour Info"
    description: "Upcoming tours and their availability"
    files:
      - label: "tour"
        name: "Tour"
        file: "static/tours.json"
        fields:
          - {label: "Tour Date", name: "date", widget: "datetime"}
          - {label: "Total Places", name: "totalPlaces", widget: "number"}
          - {label: "Filled Places", name: "filledPlaces", widget: "number"}

This doesn't seem to be what I'm looking for though, I can't seem to be able to create numerous instances of tour dates, but only one. Perhaps this is a fundamental misunderstanding of mine when it comes to collection types, but I thought I could define tour as a single file then populate it with numerous instances of tour.

Can someone point me in the right direction of how to achieve this array of tour data points without death by file?

1

1 Answers

5
votes

You can either make that collection a folder collection or use a list widget.

An example of using list, with your code:

collections:
  - name: "tourInfo"
    label: "Tour Info"
    description: "Upcoming tours and their availability"
    files:
      - label: "tour"
        name: "Tour"
        file: "static/tours.json"
        fields:
          - label: "Tour List"
            name: "tourList"
            widget: "list"
            fields:
              - {label: "Tour Date", name: "date", widget: "datetime"}
              - {label: "Total Places", name: "totalPlaces", widget: "number"}
              - {label: "Filled Places", name: "filledPlaces", widget: "number"}

So your tour date, place, etc. can be placed under a list's fields. It will look really unruly for a large amount of data though, you might want to use a custom widet to paginate it, or use folder collection.