Link items stored in a list in relation widget

I tried to access team members, which are stored in a list inside a collection, in an other collection. I’m new to Netlify CMS and somehow I don’t arrive to achieve this.

The team collection looks like this:

  - name: 'team'
    label: 'Team'
    identifier_field: 'location'
    slug: 'team-{{location}}'
    fields:
      - { label: 'Location', name: 'location', widget: 'string' }
      - label: 'Team'
        name: 'teamMember'
        label_singular: 'team member'
        identifier_field: 'email'
        widget: 'list'
        fields:
          - { label: 'Firstname', name: 'firstname', widget: 'string' }
          - { label: 'Name', name: 'lastname', widget: 'string' }
          - { label: 'Email', name: 'email', widget: 'string' }

In another collection containing services I want to link a team member to each service as the corresponding specialist.

This collection looks something like this:

  - name: 'services'
    label: 'Services'
    fields:
      - { label: 'Title', name: 'title', widget: 'string' }
      - label: 'Specialist'
        name: 'specialist'
        widget: 'relation'
        collection: 'team'
        searchFields: ['teamMember.firstname', 'teamMember.lastname']
        valueField: 'teamMember.email'
        displayFields: ['{{teamMember.firstname}} {{teamMember.lastname}}']

Somehow I don’t find the right values for searchFields, valueField and displayFields to be able to browse all team members across the teams. Maybe I have to say, that I store the team members in a list, because I need them to be easy reordered.
(Currently the dropdown menu of the Input field specialist just shows as many empty blocks as teams exist, but not the team members.)

Thank you very much for your help.

Hi @andre.lergier and welcome to the community!
We’ve just added that feature! You can now expand lists using a wildcard character *.
It doesn’t support templates yet, but you should be able to use this configuration:

collections:
  - name: 'team'
    label: 'Team'
    identifier_field: 'location'
    slug: 'team-{{location}}'
    folder: src/team
    create: true
    fields:
      - { label: 'Location', name: 'location', widget: 'string' }
      - label: 'Team'
        name: 'teamMember'
        label_singular: 'team member'
        identifier_field: 'email'
        widget: 'list'
        fields:
          - { label: 'Firstname', name: 'firstname', widget: 'string' }
          - { label: 'Name', name: 'lastname', widget: 'string' }
          - { label: 'Email', name: 'email', widget: 'string' }
  - name: 'services'
    label: 'Services'
    folder: src/services
    create: true
    fields:
      - { label: 'Title', name: 'title', widget: 'string' }
      - label: 'Specialist'
        name: 'specialist'
        widget: 'relation'
        collection: 'team'
        searchFields: ['teamMember']
        valueField: 'teamMember.*.email'
        displayFields: ['teamMember.*.firstname', 'teamMember.*.lastname']

See here https://www.netlifycms.org/docs/widgets/#relation

I would also consider using a file collection for this use case.

Note: You can still target a specific list item via teamMember.0.email

1 Like

Hi @erez!
Thank you very much for your detailed response.
Now it works - perfect! :tada:

1 Like

Woohoo! I’m glad it’s working :partying_face: Looks like we added that feature just in time :smile:

2 Likes