👀 See Sanity in action: Watch product demo 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.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.