Converting rich-text to HTML before saving to database

default discord avatar
cold8266
3 months ago
5

I am trying to add a functionality to add a product description within payload cms as rich text. But I want to convert this to HTML before saving it to the data base. Can this be done?

  • discord user avatar
    alessiogr
    Payload Team
    3 months ago

    yep! You can convert it to html in a beforeChange collection hook, and save that html into another field

  • default discord avatar
    cold8266
    3 months ago

    I am not surely how to go about this. Can you point me in the right direction or share an example @alessiogr



    Figured it out. It's working fine. Thank you!

  • default discord avatar
    lucaceck95
    2 months ago

    can you show us hou you did it? i'm interested on this..

  • default discord avatar
    cold8266
    2 months ago

    refer to this



    https://payloadcms.com/docs/fields/rich-text


    there is a section on generate html



    use this in your before change hook



    should work just fine

  • default discord avatar
    lucaceck95
    2 months ago

    ty

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.