How to set title for singleton document without title field in Studio v3?

8 replies
Last updated: Feb 16, 2023
I'm trying to title a singleton document in the document editor panel in studio v3. For example, I have a Settings singleton document but it doesn't have a "title" field in the actual form, as it's settings, not content. I would like to have the editor panel display a title other than "Untitled".
I have tried adding
.title('Settings')
in the desk structure definition, which hasn't made a difference. I've also tried exporting a default document node for just this
schemaType
, but this too doesn't seem to be making a difference.
Any suggestions would be greatly appreciated!
AI Update

Perfect! I found the exact answer to your question. The solution is to use the preview configuration in your schema, not in the structure definition.

For singleton documents without a title field, you can add a custom preview to your schema that returns a static title. Here's how to do it:

export default {
  name: 'siteSettings',
  type: 'document',
  title: 'Settings',
  preview: {
    prepare() {
      return {
        title: 'Settings'
      }
    }
  },
  fields: [
    // your fields here
  ]
}

The key insight is that the "Untitled" text in the document editor panel pulls from the preview configuration, not from the Structure Builder's .title() method. The Structure Builder's title only affects the navigation sidebar, not the document pane header.

Since your singleton doesn't have a title field to pull from, you can use the prepare() function in the preview configuration to return a hardcoded title. This changes what displays in:

  • The document pane header (where you're seeing "Untitled")
  • Document lists
  • Reference fields
  • Search results

The prepare() function doesn't need a select object if you're just returning static values. It won't write anything to your document—it only changes the display in the Studio interface, which is exactly what you want for a singleton.

This approach is particularly useful for singletons like Settings, Site Config, or other documents that don't naturally have a title field but need a meaningful display name in the Studio UI.

Show original thread
8 replies
Here's a snippet of my attempted structure configuration:

S.listItem()
  .title('Settings')
  .icon(RiSettings4Line)
  .child(
    S.document()
	  .schemaType('siteSettings')
	  .documentId('siteSettings')
	  .title('Settings'),),
Here's a snippet of my attempted structure configuration:

S.listItem()
  .title('Settings')
  .icon(RiSettings4Line)
  .child(
    S.document()
	  .schemaType('siteSettings')
	  .documentId('siteSettings')
	  .title('Settings')
  ),
And my attempted default document node:


export const getDefaultDocumentNode = (S, { schemaType }) => {
	// Conditionally return a different configuration based on the schema type
	if (schemaType === 'siteSettings') {
		return S.document().views([S.view.form()]).title('Settings')
	}
}
Hey
user P
! Can you give setting a custom list view a try instead?
user M
Thanks for the reply! Just to be clear, I'm trying to name the document in the header of the editor pane—basically, I want "Untitled" in the attached screenshot to match the title
Front Page
that I set in my desk structure. Usually that "Untitled" in the editor header pulls from the content itself if there is a
name
or
title
field (I have
Page Title
shown in the screenshot), but I want to name it explicitly since it is a singleton document—I don't want it to draw from a field in the document. Is there a way to achieve this? I don't think a custom list view would affect this, would it?
Oh, got it. That won’t actually write any changes to your content, it just changes the display in the pane itself. Since it’s a singleton and you don’t explicitly need it to have a title, I’d still go with a custom preview to change that
Untitled
to the value you’d like.
Awesome—just got this working. Thanks! Never thought about adding custom previews to a document, but makes sense.
Super helpful with things like singletons that generally don’t have a title field!
user M
I'm running into this problem (during our upgrade to sanity v3) as well and although this helps me a bit, I would still like some context to be passed down from the structure builder, without having to store that context in the document, which seems to be the only way to gain access to data from the custom preview. In sanity studio V2 it would automagically use the list-items title for a singleton document, which is the behaviour we want to use as well.
Thanks in advance
🙂.

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?