Unlock seamless workflows and faster delivery with our latest releases ā€“ get the details

Using object title as preview title in Sanity pageBuilder

7 replies
Last updated: Aug 18, 2020
Does anyone know if it is possible to use the title of the object in the preview for a pageBuilder? e.g if I have an object called 'Two Images' can I have that as the preview title
Aug 18, 2020, 8:58 AM
My page builder pulls the title for objects from the object itself
So if the object has a title set that is what is shown, see how here
https://www.sanity.io/docs/previews-list-views šŸ™‚
Aug 18, 2020, 9:13 AM
Sure, but I am not adding a title. I would like the title to be the title of the object rather than one set by the user
Aug 18, 2020, 9:16 AM
basically I just want to be able to put a string in there
Aug 18, 2020, 9:16 AM
have you tried something like this:
title: `some title`
Aug 18, 2020, 9:18 AM
Yes, I thought back ticks would work but it still says untitled for some reason
Aug 18, 2020, 9:19 AM
I think you should be able to do something like this:

  preview: {
    prepare() {
      return {
        title: "Two Images",
      };
    },
  },
Aug 18, 2020, 9:19 AM
That worked
Jayne Mast
thank you
Aug 18, 2020, 9:20 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?