I have a Jekyll website with a Netlify CMS admin page. The website supports some different languages, which I have in a _data/languages.yml file for Jekyll to use. Then in the Netlify backend there is a select widget with those same languages.
However, this means I have some duplication of this data, both my languages.yml file and the config.yml file of Netlify have the same list of languages. So I was wondering, is there a way to only have this list of languages once?
My _data/languages.yml file looks something like this:
- value: "nl"
label: "NL"
- value: "en"
label: "EN"
- value: "fr"
label: "FR"
- value: "de"
label: "DE"
- value: "ja"
label: "Japanese"
- value: "zh"
label: "Mandarin"
And in the Netlify config.yml there is:
...
label: 'Language'
name: 'language'
widget: 'select'
options:
- { label: "Dutch", value: "nl" }
- { label: "English", value: "en" }
- { label: "French", value: "fr" }
- { label: "German", value: "de" }
- { label: "Japanese", value: "ja" }
- { label: "Chinese", value: "zh" }
...
What I thought of (and why it doesn't work):
- Use liquid tags inside the
config.yml-> This is not supported, and Netlify just complains that theconfig.ymlnow starts with--- ---(the frontmatter) - Include the
languages.ymlinsideconfig.yml-> You can't "import" yml files in another one sadly
Are there any other ways that do work?
1 Answer 1
You can make your languages a file collection, which will then allow you to use a relation widget instead of the select widget with the hardcoded languages you're currently using.
If you don't want your admin user to be able to edit this language list, you can use the hide: true option in your language collection.