1

I'm trying to get Netlify CMS setup, and running into issues when I use it to create new markdown files. I tried to read through the docs to get it configured correctly but something doesn't seem to be adding up. Part of the issue seems to come from the fact that I have my own slug field that I use, and the docs say I can use fields.slug to get around conflicts, but it still puts in null when I try to use it.

Relevant parts of config.yml

collections:
  - name: "staff"
    label: "Staff Members"
    label_singular: "Staff Member"
    summary: "{{firstName}} {{lastName}}"
    folder: "content/staff"
    create: true
    slug: "{{fields.slug}}"
    media_folder: ""
    public_folder: ""
    path: "{{fields.slug}}"
    sortable_fields: ["frontmatter.email"]
    editor:
      preview: true
    fields:
      - { label: "Type", name: "type", widget: "string" }
      - {
          label: "Slug",
          name: "slug",
          widget: "string",
          pattern:
            [
              "^[a-z0-9]+(?:-[a-z0-9]+)*$",
              "A slug can have no spaces or special characters",
            ],
          required: true,
        }
      - { label: "First Name", name: "firstName", widget: "string" }
      - { label: "Last Name", name: "lastName", widget: "string" }
      - { label: "Email", name: "email", widget: "string" }
      - { label: "Body", name: "body", widget: "markdown" }

What the markdown should look like:

---
type: "staff"
slug: "jdoe"
firstName: "John"
lastName: "Doe"
email: "fake@email.com"
---

I do stuff.

What I get from Netlify CMS:

---
type: staff
slug: jdoe
firstName: John
lastName: Doe
email: fake@email.com
---

I do stuff.

The filename ends up being .md, just the extension, no filename. I did manage to get it to record the slug in the actual md, but the filename is still missing.

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Keith
  • 124
  • 1
  • 9

1 Answers1

1

Change slug: "{{fields.slug}}" to slug: "{{slug}}"

This will use the title field slug-ified for the file name. You can still have your custom slug field in your field list for other uses.

qrayg
  • 21
  • 3