Netlify-cms: Nested field access in name

Created on 12 Sep 2017  路  9Comments  路  Source: netlify/netlify-cms

It would be very nice to have the possibility to have nested fields access in field names.

Currently when I am configuring a nested field like this;

files:
      - file: 'site/content/_index.md'
        name: sections
        label: 'Sections'
        fields:
          - name: about
            label: 'About'
            widget: object
            fields:
              - { name: title, label: 'Title', widget: string }
              - { name: body, label: 'Body', widget: markdown }

It gives me the following;

-section-----
|--about----|
|----title--|
|----body---|
-------------

But if would be nice if I can just do this;

files:
      - file: 'site/content/_index.md'
        name: about
        label: 'About'
        fields:
         - { name: 'about.title', label: 'Title', widget: string }
         - { name: 'about.body', label: 'Body', widget: markdown }

And having this output;

-about-------
|--title----|
|--body-----|
-------------
api discussion feature pinned accepted

Most helpful comment

+1 for this issue. Not being able to nest fields is a big UI / UX issue in my opinion.

All 9 comments

Providing more control over the data model makes sense, agreed. Just need to figure out how the api should work, I think we can do better than dot notation (but maybe not?).

If I understand this correctly, adding this feature could help clean up the editor experience quite a lot.

Say I have the following front matter on some Hugo pages.

menu:
  main:
    weight: '1'

Setting this one integer value per page will determine both the sort order and whether the page is included in Hugo's built-in nav system. Hugo will take care of the rest using the page title as the default label for each entry and auto-generating the relative links.

Now someone please correct me if I am wrong, but to make this one field editable in NetlifyCMS, I believe I need something like the following in config.yml:

- label: "Menu"
  name: "menu"
  widget: "object"
  fields:
    - label: "Main"
      name: "main"
      widget: "object"
      fields:
        - {label: "Weight", name: "weight", widget: "number"}

This will yield a three layer deep nested object UI in NetlifyCMS to edit one single field, which will also look about as hideous as it sounds.

+1 for this issue. Not being able to nest fields is a big UI / UX issue in my opinion.

Man, just had to get a simple value nested a couple levels deep for the docs site and yeah, this is pretty silly.

screen shot 2018-04-26 at 7 48 09 pm

And it should be quite easy to implement with a library like https://github.com/developit/dlv or https://github.com/robinvdvleuten/shvl.

We're already including Lodash, so I'd expect we go with _.toPath. The challenge is in the details, e.g. collisions and validation.

@erquhart is this something we could have a fix for in 2.0? I know the status of this is "accepted"and I saw there's a some open projects to rework the API, but didn't see something that explicitly mentions this type of functionality.

If someone wants to take it on, we're open to a PR. We'd need to map when writing and also reverse map when reading, and ensure graceful handling of collisions. That said, I'd say this is ready for development.

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