Unlock seamless workflows and faster delivery with our latest releases – get the details

Is there a structure builder example where the format of each preview for the document list is modified?

4 replies
Last updated: Feb 3, 2021
Is there a structure builder example where the format of each preview for the document list is modified?
Feb 3, 2021, 3:29 AM
Example, I want to modify this to display content.title
Feb 3, 2021, 3:29 AM
If your schema looks something like this:

export default {
  name: "review",
  title: "Review",
  type: "document",
  fields: [
    {
      name: "content",
      title: "Content",
      type: "object",
      fields: [
        {
          name: 'title',
          title: 'Title',
          type: 'string',
        },
        {
          name: 'excerpt',
          title: 'Excerpt',
          type: 'string',
        }
      ]
    },
  ],
}
You can add a preview to set the title for each
review
document:

export default {
  name: "review",
  title: "Review",
  type: "document",
  fields: [
    {
      name: "content",
      title: "Content",
      type: "object",
      fields: [
        {
          name: 'title',
          title: 'Title',
          type: 'string',
        },
        {
          name: 'excerpt',
          title: 'Excerpt',
          type: 'string',
        }
      ]
    },
  ],
  preview: {
    select: {
      title: 'content.title'
    }
  }
}

Feb 3, 2021, 3:40 AM
ah brilliant, thank you. I guess I was looking in the wrong place then.
Feb 3, 2021, 3:42 AM
No problem! Thankfully, previews offer a lot of customization.
Feb 3, 2021, 3:44 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?