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.

richtext internal link is not working

default discord avatar
bhavikak.2 years ago
15

hello, in a richtext i'm give a internal link to any text. but richtext not give a href on selected text on frontend.

  • discord user avatar
    patrikkozak
    2 years ago

    Hey

    @1043125033519820902

    , would love to help here. Could you show me how you are generating your html for your richtext content on the front-end?



    You can find more information on how to get your richtext rendering on the front-end here:

    https://payloadcms.com/docs/fields/rich-text#generating-html

    Also, here is how we are setting up our RichText field on our website cms, as well as, how we then render our richtext on the front-end of our website:


    -

    https://github.com/payloadcms/website-cms/tree/main/src/fields/richText

    -

    https://github.com/payloadcms/website/tree/main/src/components/RichText

    In the above example, we are rendering link options for internal links & custom urls. Let me know if this helps! If you have any other questions or want to send me what your configuration is looking like, I'd be happy to take a look!

  • default discord avatar
    bhavikak.2 years ago

    thanks

    @1032341301619871785

    for detailed reference. i'll try with this example.



    hello

    @1032341301619871785

    when i'm giving a internal link to the text it store only this "doc": {


    "value": "64104734ff4d723aa221d90d",


    "relationTo": "subpages"


    },



    how can i get slug

  • discord user avatar
    patrikkozak
    2 years ago
    doc

    should be returning

    value

    and

    relationTo

    . However,

    value

    should be returning an object of the documents data that you are linking to - including the slug.



    e.g.

    value

    object should look something like this:



    "value": {


    "id": "64398f0d37313dd53aac55c0",


    "title": "Example Page",


    "fullTitle": "Example Page",


    "hero": {},


    "layout": [],


    "slug": "example-page",


    "meta": {},


    "breadcrumbs": [],


    "_status": "published",


    "createdAt": "2023-04-14T17:36:13.480Z",


    "updatedAt": "2023-04-14T17:36:13.712Z"


    },



    What does your richtext config look like? And what does your richtext component look like on the front-end?

  • discord user avatar
    jmikrut
    2 years ago

    this is probably an access control issue



    your

    subpage

    is not populating. are you using

    depth

    ? is this the REST API or GraphQL? if you are using depth properly, you should make sure that you have

    read

    access to your subpages collection

  • default discord avatar
    bhavikak.2 years ago

    heyy

    @364124941832159242

    i add maxdepth = 5 in payload.config.ts but it's not work



    and also i have a read access of subpages collection.



    access: {


    read: anyone,


    create: adminsAndUser,


    update: adminsAndUser,


    delete: admins,


    }, this is my access control for subpages collection



    @1032341301619871785

    thi is my richtext config look like



    and my frontend richtext component look like





  • discord user avatar
    jmikrut
    2 years ago
    @1043125033519820902

    it's not

    maxDepth

    that would do this - it would be just straight up

    depth

    maxDepth limits the total depth available for the field but you still need to pass

    depth

    , which defaults to 2



    i take it you're seeing this behavior in the REST API?

  • default discord avatar
    bhavikak.2 years ago

    i also added in rest api but it's not working



    like this

    http://localhost:8000/api/subpages/642e8045da4d9e94077bcedc?draft=true&&depth=10

    @364124941832159242

    can you tell me where i have to add depth config.

  • discord user avatar
    jmikrut
    2 years ago

    ok - your query is correct then, and you need to look at access control



    if access control does not pass for the "populated" documents, then it will remain as the ID only

  • default discord avatar
    bhavikak.2 years ago

    can you tell me how can i pass access control for the populated documents.

  • discord user avatar
    jmikrut
    2 years ago

    that depends on your

    read

    access control itself



    just to be clear, above, you said that your subpages collection has this access control:



    read: anyone,


    what is in the

    anyone

    function?

  • default discord avatar
    bhavikak.2 years ago


    heyy

    @364124941832159242

    this is my anyone hook

  • discord user avatar
    jmikrut
    2 years ago

    ok then it should not be access control that is preventing this after all



    we will likely need a minimally reproducible repo to help diagnose this further



    you should start with a fresh project, with open access control, and see that it is working



    and then add in your own code until it

    stops

    working



    and then we can help from there



    this does indeed work (we use it all the time) so it's got to be something with your implementation

  • default discord avatar
    bhavikak.2 years ago

    can you tell me my hook is correct or not.

  • discord user avatar
    jmikrut
    2 years ago

    you mean your access control?



    your access control is correct

  • default discord avatar
    bhavikak.2 years ago

    okay

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.