Netlify-cms: Allow using sub-fields of Object fields as identifier_field and slug

Created on 30 Jun 2019  路  3Comments  路  Source: netlify/netlify-cms

Is your feature request related to a problem? Please describe.

I have the following field structure:

      - label: English
        name: en
        widget: object
        fields:
          - {label: Title , name: title, widget: string}
          - {label: Body, name: body, widget: markdown}
      - label: Spanish
        name: es
        widget: object
        fields:
          - {label: Title , name: title, widget: string}
          - {label: Body, name: body, widget: markdown}

I'd like to use en.title as the identifier_field (and therefore as the {{slug}}) but doing so breaks publishing (it loads forever and in the JS console I see an error saying that I need a valid title field or a valid field name specified in identifier_field.

Here's the full collection definition I was trying to use:

  - name: "posts"
    identifier_field: "en.title"
    label: "Posts"
    label_singular: "Post"
    folder: "src/pages/posts"
    create: true
    slug: "{{year}}-{{month}}-{{day}}-{{slug}}"
    fields:
      - label: English
        name: en
        widget: object
        fields:
          - {label: Title , name: title, widget: string}
          - {label: Body, name: body, widget: markdown}
      - label: Spanish
        name: es
        widget: object
        fields:
          - {label: Title , name: title, widget: string}
          - {label: Body, name: body, widget: markdown}

Describe the solution you'd like

I'd like to use sub-fields of Object fields as the identifier_field so that slugs can be based on them.

Describe alternatives you've considered

I tried setting slug: "{{en.title}}" and that didn't work either.

As a temporary workaround, I ended up just creating a standalone "Path" field which allows manual setting of the path, so it isn't automatically generated at all.

slugs intermediate good first issue enhancement pinned accepted

Most helpful comment

Agreed, we'd definitely take a PR for this.

All 3 comments

Agreed, we'd definitely take a PR for this.

Hey @mikecrittenden. Just wanted to note that this issue is also applicable to the summary configuration option.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings