Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Creating a homepage

default discord avatar
fazyluckerlast year
14

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...)

  • default discord avatar
    zed0547last year

    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!

  • default discord avatar
    fazyluckerlast year

    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?

  • default discord avatar
    zed0547last year

    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)

  • default discord avatar
    fazyluckerlast year

    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?

  • default discord avatar
    zed0547last year

    With that specific slug, yes precisely



    You got it

  • default discord avatar
    fazyluckerlast year

    Got it thanks, I think I just was overcomplicating it for myself in my head 😄

  • default discord avatar
    zed0547last year

    It's my pleasure

  • default discord avatar
    fazyluckerlast year

    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... 🫣

  • default discord avatar
    zed0547last year

    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

  • default discord avatar
    lau1259last year

    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".

  • default discord avatar
    zed0547last year

    Well technically there's a check somewhere in the frontend that simply turns 'home' into '/' if I'm not mistaken

  • default discord avatar
    fazyluckerlast year

    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

  • default discord avatar
    zed0547last year

    Aha, I see, yeah you would need to add

    localized: true

    to that field, and also add the

    locales

    property to your Payload config



    https://payloadcms.com/docs/configuration/localization#config-options

    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

  • default discord avatar
    lau1259last year

    Thanks for theanswers, I'll look into that and see if I can implemenet it.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.