✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

How to Create an Array of Blocks

1 replies
Last updated: Jun 27, 2022
Hi folks!Can I create an array of blocks?
Jun 27, 2022, 10:45 AM
The
block
type already has to be within an array, and you can’t have an array of arrays in Sanity. Instead you could wrap the
block
in an object and put this inside of an array, as follows:
blockObject.js

export default {
    title: "Block",
    name: "blockObject",
    type: "object",
    fields: [
        {
            title: "Block Text",
            name: "blockText",
            type: "array",
            of: [{ type: "block" }],
        },
    ],
};
exampleDocument.js

export default {
    name: "Example Document",
    title: "exampleDocument",
    type: "document",
    fields: [
        {
            title: "Block Array",
            name: "blockArray",
            type: "array",
            of: [{ type: "blockObject" }],
        },
    ],
};
Jun 27, 2022, 11:06 AM

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.

Was this answer helpful?