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.

Converting rich-text to HTML before saving to database

default discord avatar
cold82662 years 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
    2 years ago

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

  • default discord avatar
    cold82662 years ago

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

    @360823574644129795

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

  • default discord avatar
    lucaceck952 years ago

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

  • default discord avatar
    cold82662 years 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
    lucaceck952 years ago

    ty

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.