Creating a schema for single pages with a page builder in Sanity.io

29 replies
Last updated: Dec 26, 2022
Hey, what would be the best way to create a schema for one single pages such as Home Page, Contact page.. pages that don't have posts.
I created a document called Pages. This document includes the Page Title, Page Description, Header, and Body. In the last section, I have a page builder called display, where I can dynamically update the page content. I can add a hero section, a content section, a call to action, or a testimonial section and drag and drop in a particular order.
Here is the link I referenced to create the Page Builder
You'll be able to create multiple pages that are each unique
dam that is cool
thanks
can the sections content also be editable?
Yes! The page builder I created is referencing other documents and it also has its own objects that I can create. I'll send an example
thanks that would help a lot
Menu, People, Content is referencing other documents while the Call to Action is an object I created specifically for the page builder
so Objects are like one off section right?
Yes thats correct. I have to import it to index.js to be able to utilize it. It won't show up on the List though since the type is not a document. It is just an object
ah okay makes sense, and can I create like a folder or group for all those section in the cms? like grouping the objects together
Object types won't show on the list, only document types. I put all my objects into a folder and the associated document in the schema folder. That way, I can know what objects are associated with a document. I hope that answered your question.
I don't see a need to display these objects if it's only be used for a specific document. If I were looking to share it with multiple documents, I'd make the type a document instead of an object
Not sure if this setup is the recommended way, but its been working for me, and I find my structure to be more organized now πŸ™‚
An ok thanks yeah that makes sense
But to confirm the user won’t be able to edit the objects using the cms right? In this set up
If I understand right, only when they are creating a document from the list "Pages". They'll have access to the object. Unless you are talking about editing code? Sorry your question confused me a bit
that makes sense thanks for the help πŸ™‚
how do I create the page to be domain/slug instead of domain/pages/slug
user C
Hello
user G
You setup routing in your frontend, not within sanity, where I would only set the slug).
I think you have so many questions about setup and structured content / the different schema types, you might want to watch some of our tutorials, so you can get a better understanding of using Sanity
πŸ™‚For example with
NextJS or other frameworks, we have a lot of videos you can watch here .
BTW: Object schema definition make it possible to reuse the configuration/definition in other parts of your schemas and embed them into the documents & other objects.
BUT:
objects
cannot be referenced, only documents can, so content is not transferable from
obj
->
obj
. (unless you go through referencing a document and its content.
Which frontend are you using then?
You explained
objects
better. Thanks Saskia! But I would definitely recommend watching tutorials first and following along. That's how I was able to get a grasp on Sanity.
I am using NextJS
user J
. I have watched some NextJs videos with sanity but will check what you have linked too
I know starting with a new stack can be frustrating, but getting the basics first will make your progress much faster πŸ™‚You can setup basic routing by just defining a
[slug].tsx
in your
./pages
folder instead of adding it into
./pages/posts/[slug].tsx
the first solution will give you
domain/SPECIFIC_SLUG
while the letter will give you
domain/posts/SPECIFIC_SLUG
hope that helps in the meantime
user C
Happy to help, but you took a lot of time to help out
user G
which is much appreciated :sanity_with_3_hearts: And I need to know how to define it πŸ˜‰ but you did the ground work!
Yeah that makes more sense thank you :)
You will see, when you get the basics, you will have a lot more fun.And if you want to learn GROQ (which is sooooo amazing IMO) i would recommend this here:

https://hdoro.dev/learn-groq

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?