Setting folder collections path overrides slug value
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
- Create a collection and set
pathtopath: "{{slug}}/_index" - Define a field for
title - Create a new record
- In a new collection create a relation widget and reference the original collection and set
valueField: {{slug}} - 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"]
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
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.
Yes. The above configuration works for me.
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.
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.
@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.
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 /.
I'm also struggling with this issue, using decap 3.9.0. Any news on this topic?