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.
Dec 25, 2022, 2:08 PM
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
Here is the link I referenced to create the Page Builder
Dec 25, 2022, 2:35 PM
You'll be able to create multiple pages that are each unique
Dec 25, 2022, 2:40 PM
dam that is cool
Dec 25, 2022, 2:43 PM
thanks
Dec 25, 2022, 2:43 PM
can the sections content also be editable?
Dec 25, 2022, 2:44 PM
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
thanks that would help a lot
Dec 25, 2022, 2:49 PM
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
so Objects are like one off section right?
Dec 25, 2022, 2:51 PM
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
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
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
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
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
An ok thanks yeah that makes sense
Dec 25, 2022, 3:10 PM
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
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
that makes sense thanks for the help πŸ™‚
Dec 26, 2022, 11:15 AM
how do I create the page to be domain/slug instead of domain/pages/slug
Dec 26, 2022, 11:16 AM
user C
Dec 26, 2022, 11:16 AM
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.
Dec 26, 2022, 1:52 PM
Which frontend are you using then?
Dec 26, 2022, 1:53 PM
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.
Dec 26, 2022, 2:13 PM
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
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
Dec 26, 2022, 2:26 PM
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
Yeah that makes more sense thank you :)
Dec 26, 2022, 2:35 PM
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
Dec 26, 2022, 3:27 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?