Decode Plain Text from CMS

Hi,

Is there a standard way to decode the HTML entities in plain text retrieved from the CMS?

I need to dynamically generate elements on some pages using data from the CMS that does not fit any of the available CMS data types. So, I’d like to store JSON in the CMS. I can do this with a plain text field, but when I get the value from the CMS via Javascript, the entities in the string are encoded. For example, if I store this in my CMS:

[["A", "1"], ["B", "2"], ["C", "3"]]

When I get the value in my custom code with:

let styles = "[Field Name]";

The retrieved text is encoded:

[["A", "1"], ["B", "2"], ["C", "3"]]

I can decode this with something like the he decoder but I thought I’d ask if there is an easier way in case I missed something in the Webflow documentation.

Thanks!

Unfortunately there is no embed field type in the CMS, however there is an embed node type available inside of the rich text element.

So you can;

  • Add a rich text field to your collection
  • Add a rich text element to your page, and bind it. Hide it if you like.
  • In the cms item, add an embed element inside of your rich text content and paste your JSON there.

it’s not super convenient to admin but it works fine and your JSON will not be HTML encoded when the page is published.

1 Like

Clever! Thanks for the tip!