Schema structure for Sanity and creating specific fields for each page in a mini-site.

9 replies
Last updated: Mar 11, 2023
Hello everyone! Needed help here.
I would like to ask something regarding the schema structure for Sanity.

I am building a mini-site for a client with few pages and I would like to create specific fields for each page, so when my client need to change the content, they just need to open the Sanity Studio online and change it from there.

So for each page, there will be specific fields. Not the kind of blog where each article contains the same field (title, author, image, etc).

How do you think I should create the schema? Do I have to create a document for every page and create 1 post? Or can I create a specific post which contains specific fields in Sanity?

Thanks in advance! Have a great day everyone.
AI Update

Perfect! This is exactly what you need - singleton documents are the ideal solution for your use case.

Since you're building a mini-site where each page has unique, specific fields (not repeating blog-style content), you should create a separate document schema for each page and configure them as singletons. This means each page type will only ever have one instance in your dataset.

Here's how to approach it:

Create a document schema for each page with its specific fields. For example:

// schemas/homePage.js
export default {
  name: 'homePage',
  title: 'Home Page',
  type: 'document',
  fields: [
    {
      name: 'heroTitle',
      type: 'string',
      title: 'Hero Title'
    },
    {
      name: 'heroImage',
      type: 'image',
      title: 'Hero Image'
    },
    // ... other fields specific to home page
  ]
}

// schemas/aboutPage.js
export default {
  name: 'aboutPage',
  title: 'About Page',
  type: 'document',
  fields: [
    {
      name: 'companyHistory',
      type: 'text',
      title: 'Company History'
    },
    // ... other fields specific to about page
  ]
}

Configure them as singletons in your sanity.config.js to prevent creating multiple instances. The singleton document pattern requires three configurations:

  1. Structure Builder - creates direct links to each page
  2. Template filtering - removes these from the "New document" menu
  3. Document actions - removes duplicate/delete actions

The easiest way is to use the sanity-plugin-singleton-tools plugin, which handles all this configuration automatically.

Important: Create one instance of each document in the Studio BEFORE configuring them as singletons. Once configured, the UI to create new instances will be disabled.

This approach gives your client a clean, organized Studio interface where they can click directly into "Home Page", "About Page", etc., and edit the specific fields for each page without any confusion about creating/managing multiple posts.

If you're only going to have a few pages and they're all unique, I would think you would just build individual document types.
You might be able to have a single document type called Page and then implement a "page builder", but I suppose that would depend on other factors.
Thanks for your reply User.
So what you are suggesting is I create few document types and for each document types, I should create 1 post. I will then fetch the data for each page from that post.

As for the page builder, could you explain to me as to how to do page builder inside Sanity?

Thanks a lot! Really appreciate it.
Well, first, you should know I'm still learning Sanity myself. But based on your original question, those are the two ways I could think of to do it. The first way uses unique document types created as singletons. You wouldn't "create 1 post". You would just display the document editor directly when you click on that page. To do that, you will need to create your own desk structure. The page builder method would (theoretically) allow you to create one document type. Then you would create custom modules to drag into the page builder object. Just search the docs for page builder or google around for examples. It sounds like the first approach would make more sense if you're just looking to use text fields for each page.
Yes the first one is the one i’m looking for! I have just read the documentations for Singleton Document. Seems quite tricky but I’ll give it a shot. Thanks a lot User!
That's actually the easier (or less complex) of the two. Give it a shot and let me know if you need more direction.
Perfect! Really appreciate your help!
My pleasure! Have fun!

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?