I feel like I'm being really stupid here but I can't seem to find the answer on the docs. How do I create a homepage? Or static routes in general.
I tried creating a new page from the admin panel but I don't see how to set it as the homepage (or an about page, or a contact page etc...)
Hey
@230766082963537921,
I'll refer you to the website template which shows how you can create pages, posts, and projects via the CMS and then render them in your frontend:
https://github.com/payloadcms/payload/tree/main/templates/website/src/app/(frontend)
As for purely static pages, nothing much changes, you have your own frontend where you controls the elements!
Appreciate it, is that the right link though? It's just a file directory, or am I meant to be looking at one of the files in there?
Yeah, so for home page have a look at how the page in the [slug] directory works for example
There you're shown how to:
- generateMetaData
- Access payload dynamically
- Use the local api to perform a find for a page with a slug
- Return a client component that builds out the page itself (in page.client.tsx)
So, if I'm understanding it right and to oversimplify it somewhat, it's just a case of getting the url parameter, for example "/about" then filtering and returning an item from the pages collection with a specific title?
With that specific slug, yes precisely
You got it
Got it thanks, I think I just was overcomplicating it for myself in my head 😄
It's my pleasure
Okay, so it's actually just clicked. I don't know what I was thinking. By default the homepage is whatever page you title "home" then for the page that appears at "/about" you just have to create an item in the pages collection titled "about". it's actually so simple and I was here trying to figure out how to build a function myself to get specific pages based on the url... 🫣
Yep! With Payload things will start to click and eventually you'll never be able to go back is what I've found
Incedibly powerful technology
Hey do either of you know if you can change the homepage to something with a different title? I'm working on a site in another language and , if possible, I want the slug and title to be the localized version of "home".
Well technically there's a check somewhere in the frontend that simply turns 'home' into '/' if I'm not mistaken
I think he means more about from the view in the admin panel, so you'd see the page in the collections labelled "home". I've seen there is i8n across payload but beyond that I'm still getting to grips with everything so can't be much help sorry
Aha, I see, yeah you would need to add
localized: trueto that field, and also add the
localesproperty to your Payload config
In Payload you havbe I18n which is specifically for the admin dashboard and Localization which is for your content, that's the major distinction between the two
Thanks for theanswers, I'll look into that and see if I can implemenet it.
Star
Discord
online
Get dedicated engineering support directly from the Payload team.