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.

How do get document data within Collection custom component?

default discord avatar
plaguefpslast year
8

I'm trying to create a "view page" button using a UI field within the relevant collection and I'm not sure how I'm supposed to get any of the document data I need to generate the URL

  • default discord avatar
    notchrlast year
    @683517071749021779

    You should be able to use Hooks to get document data



    https://payloadcms.com/docs/admin/hooks

    https://payloadcms.com/docs/admin/hooks#usedocumentinfo
  • default discord avatar
    plaguefpslast year

    Yeah I saw the documention on this hooks existence but the only valuable information I could find returned from this hook was the doc's slug, but, I need more than that.



    Specifically I need the doc's slug and the id of the category it is related to so I can fetch that category and generate the URL since the URL structure is

    https://mywebsite/category/slug
  • default discord avatar
    notchrlast year

    You only got the slug back?



    Can I check out your usage of the hook?

  • default discord avatar
    plaguefpslast year

    No I got a bunch of other values, but, none of them looked like it would give me what I needed, kinda wish the docuementation explained what some of the values are

  • default discord avatar
    notchrlast year

    I can review it with you if you post the returned value here

  • default discord avatar
    plaguefpslast year

    Oh on second glance it may be the

    initialData

    , if not I can post the returned value, let me test this real quick though

  • default discord avatar
    notchrlast year

    Sure thing

  • default discord avatar
    plaguefpslast year

    Yup, the

    initialData

    gets me the docs fields and values, this is what I needed I apologize for not seeing this value during my first pass and making a post about it lol

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.