I have json content as an array of objects in my gatsby site in the format
[{text: 'lorem', image:'some Image'}, {text: 'lorem', image:'some Image'},
… ]
I tried this option, using the list widget in config.yml
- label: "Products Section"
name: "Products"
file: "src/content/productData.json"
fields:
- label: "Products"
name: "productList"
widget: "list"
fields:
- {label: "Caption", name: "text", widget: string,}
- {label: Image, name: image, widget: image}
I receive an empty list with the above option.
Are there any changes that can be made to get it to work? (in either the config or the JSON file structure)
I found part of the answer here:
This appears to be a repeat of
Hi, I have a .json file containing a list of items that populate a menu. The basic structure is:
[
{"slug": "content", "title": "Contact us"},
{"slug": "about", "title": "About us"}
...
]
I’ve tried to recreate this array of objects within the my .yml file like so:
collections:
- name: "menus"
label: "Menus"
files:
- label: "Menu"
name: "menu"
file: "_menu/urls.json"
widget: "list"
fields:
- label: "Menu"
name: "menu"
wi…
So basically netlifycms does not support editing arrays at root level
The issue is open here
opened 09:07AM - 16 Aug 17 UTC
kind: feature
status: accepted
status: needs design
area: configuration
area: formats
pinned
<!--
If you are reporting a new issue, make sure that we do not have any duplic… ates
already open. You can ensure this by searching the issue list for this
repository. If there is a duplicate, please close your issue and add a comment
to the existing issue instead.
If you suspect your issue is a bug, please edit your issue description to
include the BUG REPORT INFORMATION shown below. If you fail to provide this
information within 7 days, we cannot debug your issue and will close it. We
will, however, reopen it if you later provide the information.
If you have an issue that can be shown visually, please provide a screenshot or
gif of the problem as well.
---------------------------------------------------
BUG REPORT INFORMATION
---------------------------------------------------
Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST
-->
**- Do you want to request a *feature* or report a *bug*?**
Feature
**- What is the current behavior?**
it seems to be impossible to create data files with a list at root level:
```yaml
- nav_object_1
- nav_object_2
```
The current work-around is to use
```yaml
navigation:
- nav_object_1
- nav_object_2
```
However, this may require a change of the template that may be part of libraries (jekyll theme gems).
**- What is the expected behavior?**
I can just create lists also on root level.
But I would still like to know how I can change the json file structure to be able to use the list widget properly
You should name the list like:
"productList": [{text: 'lorem', image:'some Image'}, {text: 'lorem', image:'some Image'}
1 Like
That was fast, I implemented this and it works like a breeze.
Thanks @tomrutgers
This is why I like netlify
2 Likes