DEV Community

Discussion on: Creating a blog with NuxtJS and Netlify CMS - 2

Collapse
 
frikishaan profile image
Ishaan Sheikh

Thanks, Martino for reading the post!
In order to handle categories, you have to create a new collection and create a new field with relation type widget (see links) in the blog collection.

....
collections:
  - name: "blog"
    label: "Blog"
    format: "json"
    folder: "assets/content/blog"
    create: true
    slug: "{{slug}}"
    editor:
      preview: true
    fields:
      - { label: "Title", name: "title", widget: "string" }
      - { label: "Publish Date", name: "date", widget: "datetime" }
      - {
          label: "Category",
          name: "category",
          widget: "relation",
          collection: "categories",
          searchFields: ["name"],
          valueField: "name",
          multiple: true,
        }
      - { label: "Body", name: "body", widget: "markdown" }

  - name: "categories"
    label: "Categories"
    folder: "assets/content/category"
    create: true
    slug: "{{slug}}"
    identifier_field: name
    fields:
      - { label: "Name", name: "name", widget: "string" }
      - { label: "Image", name: "image", widget: "image", required: false }
      - { label: "Description", name: "description", widget: "markdown" }
.....

I hope this will help.

Collapse
 
romam88 profile image
Martino Roma

Great, thanks