Creating a schema for single pages with a page builder in Sanity.io
29 replies
Last updated: Dec 26, 2022
R
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.
S
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.
S
Here is the link I referenced to create the Page Builder
S
You'll be able to create multiple pages that are each unique
R
dam that is cool
R
thanks
R
can the sections content also be editable?
S
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
R
thanks that would help a lot
S
Menu, People, Content is referencing other documents while the Call to Action is an object I created specifically for the page builder
R
so Objects are like one off section right?
S
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
R
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
S
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.
S
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
S
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 π
R
An ok thanks yeah that makes sense
R
But to confirm the user wonβt be able to edit the objects using the cms right? In this set up
S
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
R
that makes sense thanks for the help π
R
how do I create the page to be domain/slug instead of domain/pages/slug
R
user C
S
Hello
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:
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:
objectscannot be referenced, only documents can, so content is not transferable from
obj->
obj. (unless you go through referencing a document and its content.
S
Which frontend are you using then?
S
You explained
objectsbetter. 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.
R
I am using NextJS
user J
. I have watched some NextJs videos with sanity but will check what you have linked too S
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].tsxin your
./pagesfolder instead of adding it into
./pages/posts/[slug].tsxthe first solution will give you
domain/SPECIFIC_SLUGwhile the letter will give you
domain/posts/SPECIFIC_SLUGhope that helps in the meantime
S
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!R
Yeah that makes more sense thank you :)
S
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
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.