DEV Community

loading...

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

Collapse
romam88 profile image
Martino Roma

Hello, thank you so much for the syntethic and precise post! I was wondering if you have time to share how to handle categories and category pages.

Collapse
sheikh_ishaan profile image
Ishaan Sheikh Author

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