How to store HTML code in an object field and render it at runtime on the page?
Hello Community,
I need to store a snippet of HTML code (e.g., a button or formatted content) into a field of an object (e.g., a text or string field). Later, I want to render this HTML dynamically on a page at runtime.
What’s the best way to store the HTML safely and then render it so that it's interpreted as actual HTML (not plain text) in the UI?
Are there any security or encoding considerations I should keep in mind?
Thanks in advance!
Like
An easy no code way would be to bind the value to a read-only Rich Text control on the page. It will display the HTML as HTML.
Otherwise, you'd have to create your own custom control for it.
Hello Ajay,
Here is the article that contains the explanation and example of how to create custom control
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platform/8.1/front-end-development/classic-ui/controls/examples/add-a-control-to-a-record-page
Also inside your custom control implementation you can add HTML value validation and remove any script elements to provide the level of security.
Hi Iryna,
Is above link, you provided, applied for Freedom UI module?
The information and example for Freedom UI you can find here:
https://academy.creatio.com/docs/8.x/dev/development-on-creatio-platfor…
This simple example of an IFRAME control could easily be adapted to simple output a div containing the custom HTML instead, plus you'd just bind the column containing the HTML to the control. https://customerfx.com/article/embedding-an-iframe-on-a-creatio-freedom-ui-page/
A full component would likely be a better route, but this simpler option coudl still get the job done.
Ryan