Hello! Could someone tell me how can I save the Rich Text content to DB as a text (example: content: "<p>Lorem </p>") instead of an array of objects? Thanks!
Hey @.tg888 - couple things to note here:
Most of the time, this kind of approach is not a good idea. This should really be done on your frontend in most cases. Here is an example of how we handle rich text on our website:
The benefits of the above are that you can map React components to different elements / leaves and maintain a high degree of control.
And have dynamic relations e.g. links to pages, upload references, etc.
Here is an example of how we handle rich text on the Payload side:
Also, it's worth noting that HTML is not as portable, in other words, it doesn't work in native apps (mobile, non-web-based platforms).
But if you really wanted to store the HTML, then you could do it with a virtual field where you have an afterRead hook that automatically serializes and stores HTML from rich text JSON. You should not, however, change the way the rich text is stored itself.
We have a virtual field example in our examples folder as well if you want to check it out:
If you have any other questions, let me know!
Thank you very much!