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.

Do I use blocks or is there another way?

default discord avatar
taun21602 years ago
2

Hi. I'd like to create a portfolio website that contains portfolio items, blog, media modal etc. Attached are screenshots. My current noob understanding of Payload is that I can create a Layout config that is embedded into the Page config and from that Layout I can select a Block config and that block will be rendered to the Page via [...slug]. Is that necessary for my situation? For example, I'd like to create a home page that contains a portfolio hero -their portfolio pieces - titles and cover image. They must be able to configure that content display to their preferences. Will it be simpler to create a seperate page (outside of [...slug]) and somehow link that content to a config? I don't understand how that works, or if it's preferable. Is the block rendering approach the go-to?

  • default discord avatar
    hades2000822 years ago

    I like to think of blocks as a kind of limited page-builder.



    Each block has it's own content model, and you simply render the blocks in order in your chosen location.



    For your use-case I would assume that you have a collection of "Portfolio Items".



    I'd create a block with a field that allows the selection of one or more portfolio items using the relationship field type (

    https://payloadcms.com/docs/fields/relationship

    ). When rendering this block you qill fetch the selected portfolio items as needed.



    For the hero a "Hero banner" block with fields for title, text, image, CTA, etc.



    Then, on your "homepage" you have a "Blocks" field that allows the selection of these blocks and just render them in your front-end in the order they are added to the homepage item.

  • default discord avatar
    taun21602 years ago

    Great, thanks a lot for that thorough reply

    @365498720726286349

    . I see Payload has a 'renderBlog' component within their website, when I get to it I'll take a look and see what approach they're using for blog posts.. I assume it's a similar logic as rendering blocks.



    @365498720726286349

    - do you have any ideas of how I can solve this error?:



    https://discord.com/channels/967097582721572934/1098599462001184889

    I renamed the Component and Config files within the block folder, that shouldn't matter right?



    https://github.com/taunhealy/WhitePolaroids1/blob/master/blocks/PortfolioHero/PortfolioHero_Config.ts
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.