decap-cms icon indicating copy to clipboard operation
decap-cms copied to clipboard

Setting folder collections path overrides slug value

Open hursey013 opened this issue 5 years ago • 8 comments

Describe the bug When using the folder collections path option, the value of slug becomes that of path rather than just the slugified version of title or identifier_field.

To Reproduce

  1. Create a collection and set path to path: "{{slug}}/_index"
  2. Define a field for title
  3. Create a new record
  4. In a new collection create a relation widget and reference the original collection and set valueField: {{slug}}
  5. Save a record in the new collection

Expected behavior The value of of the relation widget to be just the slugified version of title, instead it's the entire path as defined in path (my-title-slug/_index).

Screenshots

Applicable Versions:

  • Netlify CMS version: 2.10.55

CMS configuration

collections:
  - name: "topics"
    label: "Topics"
    folder: "content/topics"
    path: "{{slug}}/_index"
    create: true
    fields:
      - label: "Topic Title"
        name: "title"
        widget: "string"
        hint: "Short, topical, no acronyms."

  - name: "events"
    label: "Events"
    label_singular: "Event"
    folder: "content/events"
    fields:
      - label: "Topics"
        name: "topics"
        widget: "relation"
        collection: "topics"
        searchFields: ["title"]
        valueField: "{{slug}}"
        displayFields: ["title"]

hursey013 avatar Jul 28 '20 19:07 hursey013

I am also facing similar issue. Here is my configuration.

backend:
  name: git-gateway
  branch: master
media_folder: 'static/images'
public_folder: '/images'
slug:
  encoding: "ascii"
  clean_accents: true
  sanitize_replacement: "-"
collections:
  - name: 'post'
    label: 'Posts'
    folder: 'content/posts'
    path: '{{year}}/{{month}}/'
    create: true
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
    editor:
      preview: false
    fields:
      - { label: 'Title', name: 'title', widget: 'string' }
      - { label: 'Publish Date', name: 'date', widget: 'datetime' }
      - { label: 'Body', name: 'body', widget: 'markdown' }
      - { label: 'tags', name: 'Tags', widget: 'list', default: [] }
      - { name: 'sidebar', widget: 'hidden', default : 'right' }
      - { name: 'widgets', widget: 'hidden', default : ['recent', 'taglist'] }

When I publish an article, it creates a file under the folder as .md. See tree output below.

-> tree . -a
.
└── 07
    └── .md

kundanjha101 avatar Jul 30 '20 18:07 kundanjha101

Hi @kundanjha101, your issue seems different as it doesn't include the relation widget. I think you should try the following config: path: '{{year}}/{{month}}/{{slug}}'

If that doesn't work, please open a new issue.

erezrokah avatar Aug 02 '20 10:08 erezrokah

Yes. The above configuration works for me.

kundanjha101 avatar Aug 02 '20 15:08 kundanjha101

I've the same issue as @hursey013, when accessing the slug value in a relation field. It's not the end of the world, and I can understand the reason why it works like that, but it's inconsistent with the rest of the application and requires messy logic that shouldn't be necessary. Really, the whole slug/file-name thing in the CMS is bit clumsy, but I notice in other issues that there's been considerable discussion about it.

rumack avatar Apr 01 '21 14:04 rumack

Hi,

My issue is that if I use the following configuration for the slug

slug: "{{speciality}}/{{proceduresCategories}}/{{procedure}}"

It creates the correct folders and filename but the CMS front-end is unable to read the collection content. Content is created but you cannot go back to edit the content as it not listed. Using the path configuration like

path: "{{speciality}}/{{proceduresCategories}}/{{procedure}}"

the second folder, proceduresCategories, is not created at all. Very frustrating, any idea how to get around this issue.

nolafs avatar Jun 09 '21 15:06 nolafs

@hursey013 I'm facing the exact same issue. Did you find a workaround?

EDIT: As a temporary fix, I changed the relation to a select widget using fixed options with the expected values (you have to update the list when the collection changes). Far from good a solution, but it's something.

butaca avatar Mar 29 '23 02:03 butaca

I'm also seeing the same issue. The path of the relation is being recorded instead of the slug, i.e. the /_index get appended to it. Using {{title}} instead is more brittle, especially if the title contains a /.

anjackson avatar Sep 11 '25 13:09 anjackson

I'm also struggling with this issue, using decap 3.9.0. Any news on this topic?

cyrill-intersim avatar Nov 09 '25 20:11 cyrill-intersim