👋 Next.js Conf 2024: Come build, party, run, and connect with us! See all events

How to name a singleton document in the Sanity.io document editor panel

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!
Jan 16, 2023, 10:17 PM
Here's a snippet of my attempted structure configuration:

S.listItem()
  .title('Settings')
  .icon(RiSettings4Line)
  .child(
    S.document()
	  .schemaType('siteSettings')
	  .documentId('siteSettings')
	  .title('Settings'),),
Jan 16, 2023, 10:18 PM
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')
	}
}
Jan 16, 2023, 10:20 PM
Hey
user P
! Can you give setting a custom list view a try instead?
Jan 17, 2023, 10:11 PM
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?
Jan 17, 2023, 11:17 PM
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.
Jan 17, 2023, 11:23 PM
Awesome—just got this working. Thanks! Never thought about adding custom previews to a document, but makes sense.
Jan 19, 2023, 5:40 PM
Super helpful with things like singletons that generally don’t have a title field!
Jan 19, 2023, 5:46 PM
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
🙂.
Feb 16, 2023, 9:26 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?