How to create a schema for tabbed content in Sanity.io
3 replies
Last updated: Sep 28, 2021
D
Hello all, I'm currently trying to create a schema for tabbed content which would hold an array of questions and answers, but I received this error
Found array member declaration of type "array" - multidimensional arrays are not currently supported by Sanitywhich I understand, but my question would is... what be the best way to setup something like this? Here's what I was trying to do:
export default { name: "tabbedContent", title: "Tabs", type: "array", of: [ { name: "tabTitle", title: "Tab Title", type: "localeString", }, { name: "tabContent", title: "Tab Content", description: "Questions and answers", type: "array", of: [ { name: "qna", title: "Questions and Answers", type: "questionAndAnswer", }, ], }, ], };
Sep 28, 2021, 5:45 PM
Hi User. If you wrap
tabContentin an object so that it’s the object that’s the child of
tabbedContent, the first limitation seen here will no longer apply and this should work (assuming
tabbedContentisn’t a direct child of an array itself too, in which case you’d want to do the same there).Hi User.
Sep 28, 2021, 6:05 PM
D
Hey User, thanks so much for taking the time to reply and help out! So, the way I ended up setting it up is not my favourite, but it works. One of the issues as you mentioned was the parent of
tabbedContentwas also an array(page builder).What I ended up doing was this
_export_ _default_ { name: "tabbedContent", title: "Tabs", type: "object", preview: { select: { name: "tabTitle", }, prepare: ({ name }) => ({ title: `${name.en}`, }), }, fields: [ { name: "tabTitle", title: "Tab Title", type: "localeString", }, { name: "tabContent", title: "Tab Content", description: "Questions and answers", type: "array", of: [ { name: "qna", title: "Create new FAQ", type: "questionAndAnswer", }, ], }, ], }; ```
Sep 28, 2021, 8:14 PM
You’re right—it does add some clutter to the code by requiring that additional object. Your solution looks good and I’m glad you’re up and running!
Sep 28, 2021, 8:16 PM
Sanity– build remarkable experiences at scale
Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.