Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting folder collections path overrides slug value #4092

Open
hursey013 opened this issue Jul 28, 2020 · 6 comments
Open

Setting folder collections path overrides slug value #4092

hursey013 opened this issue Jul 28, 2020 · 6 comments
Labels
area: slugs status: unconfirmed type: bug code to address defects in shipped code

Comments

@hursey013
Copy link

hursey013 commented Jul 28, 2020

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"]
@erezrokah erezrokah added type: bug code to address defects in shipped code status: unconfirmed area: slugs labels Jul 29, 2020
@kundanjha101
Copy link

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

@erezrokah
Copy link
Contributor

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.

@kundanjha101
Copy link

Yes. The above configuration works for me.

@rumack
Copy link

rumack commented Apr 1, 2021

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.

@nolafs
Copy link

nolafs commented Jun 9, 2021

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.

@butaca
Copy link

butaca commented Mar 29, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: slugs status: unconfirmed type: bug code to address defects in shipped code
Projects
None yet
Development

No branches or pull requests

6 participants