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.
Dec 25, 2022, 2:08 PM
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.
Dec 25, 2022, 2:34 PM
S
Here is the link I referenced to create the Page Builder
Dec 25, 2022, 2:35 PM
S
You'll be able to create multiple pages that are each unique
Dec 25, 2022, 2:40 PM
R
dam that is cool
Dec 25, 2022, 2:43 PM
R
thanks
Dec 25, 2022, 2:43 PM
R
can the sections content also be editable?
Dec 25, 2022, 2:44 PM
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
Dec 25, 2022, 2:48 PM
R
thanks that would help a lot
Dec 25, 2022, 2:49 PM
S
Menu, People, Content is referencing other documents while the Call to Action is an object I created specifically for the page builder
Dec 25, 2022, 2:50 PM
R
so Objects are like one off section right?
Dec 25, 2022, 2:51 PM
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
Dec 25, 2022, 2:54 PM
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
Dec 25, 2022, 2:55 PM
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.
Dec 25, 2022, 3:02 PM
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
Dec 25, 2022, 3:06 PM
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 π
Dec 25, 2022, 3:08 PM
R
An ok thanks yeah that makes sense
Dec 25, 2022, 3:10 PM
R
But to confirm the user wonβt be able to edit the objects using the cms right? In this set up
Dec 25, 2022, 3:11 PM
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
Dec 25, 2022, 3:21 PM
R
that makes sense thanks for the help π
Dec 26, 2022, 11:15 AM
R
how do I create the page to be domain/slug instead of domain/pages/slug
Dec 26, 2022, 11:16 AM
R
user C
Dec 26, 2022, 11:16 AM
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.
Dec 26, 2022, 1:52 PM
S
Which frontend are you using then?
Dec 26, 2022, 1:53 PM
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.
Dec 26, 2022, 2:13 PM
R
I am using NextJS
user J
. I have watched some NextJs videos with sanity but will check what you have linked too Dec 26, 2022, 2:15 PM
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
Dec 26, 2022, 2:26 PM
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!Dec 26, 2022, 2:28 PM
R
Yeah that makes more sense thank you :)
Dec 26, 2022, 2:35 PM
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
Dec 26, 2022, 3:27 PM
Sanityβ build remarkable experiences at scale
The Sanity Composable Content Cloud is the headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.