Issue with adding a rich text block inside an array of structured content.

7 replies
Last updated: Oct 2, 2023
Hey there! How to add a rich text block inside an array of structured content?I have this object for the content:


{
      title: "Content",
      name: "content",
      type: "array",
      group: "countryInfo",
      of: [
        // { type: "block" },
        { type: "textBlock" },
        { type: "image" },
        { type: "speedTest" },
        { type: "thePricingTable" },
      ],
    },
the `textBlock`object is this:

export default {
  name: "textBlock",
  title: "Text Block",
  type: "array",

  of: [{ type: "block" }],
};
but i get this error:
Oct 2, 2023, 12:32 PM
hey, did you add the textBlock to the /schema/ index.js(ts) file ?
you have to register all schemas there for sanity to find them
Oct 2, 2023, 12:57 PM
Hey, yes i did. I think the issue is that
textBlock
is an array and
content
is also an array. So it means array within an array, so maybe its not possible. I thought maybe there is another way how to approach this.
Oct 2, 2023, 1:03 PM
the error here indicates that what ever you are trying to map is not an array. Make sure you are mapping the right thing
Oct 2, 2023, 1:06 PM
ok, it just worked after 2 days of trying lol
Oct 2, 2023, 1:14 PM
textBlock
should be an object instead of an array
Oct 2, 2023, 1:15 PM
export default {
  name: "textBlock",
  title: "Text Block",
  type: "object",
  fields: [
    {
      name: "textBody",
      title: "TextBody",
      type: "array",

      of: [{ type: "block" }],
    },
  ],
};

Oct 2, 2023, 1:15 PM
cool, good you worked it out..
yeah 2D arrays are not supported, the workaround is using and object/array combo..
Oct 2, 2023, 1:23 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.

Was this answer helpful?