✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Creating single use documents in Sanity.io and resolving issues with edit-only fields.

13 replies
Last updated: Oct 11, 2022
Hi everyone!Does anyone know how I create single use documents? For example, for general company info like uploading the logo, company addresses etc. Or another use case, would be for a homepage of a website – whereby you'd only allow one – basically a single object, rather than an array
Oct 7, 2022, 2:22 PM
A ‘singleton’ is what you’re looking for. This might help: https://www.sanity.io/docs/create-a-link-to-a-single-edit-page-in-your-main-document-type-list
Oct 7, 2022, 2:24 PM
Amazing! that was super quick too. Thank you
user J
- i am new to Sanity so still getting my head around things
Oct 7, 2022, 2:26 PM
No problem!
Oct 7, 2022, 2:28 PM
user J
so I've followed the instructions and seem to have it set up. However, the fields within the document are edit only and I can't understand why. Are you familiar with this situation and why that might be?
Oct 7, 2022, 3:27 PM
Can you share your schema?
Oct 7, 2022, 3:32 PM
Sure. here you go
Oct 7, 2022, 3:37 PM
hmm, schema looks okay at first glance. Try adding back in
in this line:
__experimental_actions: [/*'create',*/ 'update', /*'delete',*/ 'publish'],
Update that document, then comment it back out again. I think it’s because right now that document doesn’t exist
Oct 7, 2022, 4:39 PM
Cory’s suggestion gets at the likely cause; the document needs to exist before setting
in the schema.
Oct 7, 2022, 4:54 PM
user A
user J
that worked! thank you. That documentation might need to be tweaked then.
Oct 10, 2022, 1:51 PM
One thing though, as there is no title, is there a way to 'hardcode' the title in? looks a bit wierd remaining as 'untitled'
Oct 10, 2022, 1:52 PM
I wonder, is there a way of getting around having to enable and then disable 'creation'? I expect this will become problematic when new environments are created. I am also trying to set up a boilerplate sanity schame set up to use on many sites and this is something that could be easily forgotten and a niggly, seemingly hacky code change (and revert) that needs doing every time to establish the single document in the database.
Oct 10, 2022, 4:38 PM
I usually make a little node script that goes and creates all the necessary singleton documents.
Oct 10, 2022, 5:25 PM
Ah clever. sounds a bit too advanced for my level though. Is is an easy drop in script, or does it require some back end dev experience to set up?
Oct 11, 2022, 2:14 PM

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?