Structured Content 2022: Join our conference to explore fresh perspectives on content and digital experiences →

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.io: Get the most out of your content

Sanity.io is a platform to build websites and applications. It comes with great APIs that let you treat content like data. Give your team exactly what they need to edit and publish their content with the customizable Sanity Studio. Get real-time collaboration out of the box. Sanity.io comes with a hosted datastore for JSON documents, query languages like GROQ and GraphQL, CDNs, on-demand asset transformations, presentation agnostic rich text, plugins, and much more.

Don't compromise on developer experience. Join thousands of developers and trusted companies and power your content with Sanity.io. Free to get started, pay-as-you-go on all plans.