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 the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?