Netlify-cms: Config templates/partials

Created on 30 Oct 2020  ·  4Comments  ·  Source: netlify/netlify-cms

Is your feature request related to a problem? Please describe.
Kind of… Let's say you have multiple collections in your config file. And 2 of them share the exact same structure. Currently, we have to duplicate all the fields from one to another. Ideally, we would create a _config-partial.yml which could then be referred to multiple times across config.yml.

Why:

  • Reusability — Prevents repetition of fields configs that are exactly the same for multiple collections.
  • Maintainability — Huge config files are never pretty to maintain. Smaller chunks would make for easier maintenance.

Describe the solution you'd like
Some way to refer to a file structure, for instance:

# config.yml
collections:
  - name: 'my_collection'
    label: 'My collection'
    folder: '_things'
    fields_partial: './configs/_title_url.yml'
# _title_url.yml
fields:
  - name: 'title'
    # …
  - name: 'url'
    # …

Describe alternatives you've considered
Alternatively, and for ultimate maintainability, but perhaps harder to implement would be to allow for something like this _anywhere_ in config.yml:

# config.yml
collections:
  config_partial: './configs/_my_collection.yml'
# _my_collection.yml
- name: 'my_collection'
  label: 'My collection'
  folder: '_things'
  config_partial: '_title_url.yml' # same file as above
duplicate feature

Most helpful comment

Related to (and quite possibly a duplicate of) #1342

All 4 comments

In the meantime YAMLs alias nodes might d the job (https://yaml.org/spec/1.2/spec.html#id2786196)

Related to (and quite possibly a duplicate of) #1342

This is covered an #1342 and there are possible solutions in that issue

@ChrisLasar That was not exactly what I wanted, but that's what I needed now.
At least until we have #1342 merged in, this is going to be _really_ helpful!

Thanks! Have some 🍰

Was this page helpful?
0 / 5 - 0 ratings