embedding HTML by passing text variable to expression

hi,

I need to consume a REST API that gives me HTML string as response and show that HTML on outsystems screen.

I understand when embedding HTML I can use expression with "Escape Content" set to "No" and it does work when I simply pass a HTML string directly to expression value.


However, when I let text type variable intercept, then pass the variable to expression value, expression value seems to be interpreted as text type and becomes quoted.

(so the html in browser's developer's mode looks like "<div>~~~</div>" and <div>~~~</div> literals are rendered on my screen)


Since my objective HTML comes from REST API response, it is difficult to not let any variable intercept before passing to expression value.

Is there a work-around like other variable types or attribute settings?


thanks in advance

Hi Sho Katayama,

What do you mean by "variable intercept"?

Your expressions can have their Escape Content property set to No, in which case their contents will not be sanitised/encoded by the platform. It doesn't really matter if the expression's Value property was assigned the output of the REST API or if you just assigned it a variable... Can you explain better what you are doing between receiving your HTML and displaying it in an Expression (eventually screenshots of the several steps can be helpful)

Jorge Martins wrote:

Hi Sho Katayama,

What do you mean by "variable intercept"?

Your expressions can have their Escape Content property set to No, in which case their contents will not be sanitised/encoded by the platform. It doesn't really matter if the expression's Value property was assigned the output of the REST API or if you just assigned it a variable... Can you explain better what you are doing between receiving your HTML and displaying it in an Expression (eventually screenshots of the several steps can be helpful)

hi Jorge,

I'm sorry to confuse you. Let me post some screenshots.


 1-1. this is how I'm consuming the API and converting the response to HTML string


1-2. this is what is assigned to local text variable (partly covered due to private infomation)


2-1. when rendering, this works


2-2. but this does not


3. they are rendered like this


I hope this helps.

Solution

Hi,

The problem is the text you are passing, that is already escaped.

For example, your text has < instead of <

This will make the browser interpret it as TEXT, instead of HTML.
While the Escape Content property is set correctly, the browser can't really render the content of the expression as HTML.

You need to "fix" your content, "unescaping" it before using it as the variable content, so that when the server uses its content to render the page, it uses <div instead of <div

Cheers.

Solution

Eduardo Jauch wrote:

Hi,

The problem is the text you are passing, that is already escaped.

For example, your text has < instead of <

This will make the browser interpret it as TEXT, instead of HTML.
While the Escape Content property is set correctly, the browser can't really render the content of the expression as HTML.

You need to "fix" your content, "unescaping" it before using it as the variable content, so that when the server uses its content to render the page, it uses <div instead of <div

Cheers.

hi Eduardo,

Thanks for the help!


Unfortunately the API is from third party so I cannot fix its response. 

That leaves me having to have to "decode" the response, is how I understood my situation.


A decoder suggestion would be very nice. I could only find forge "HTML decoder" published in 2011...

(or should this be a new topic?)


many thanks

Hi Sho,

Don't know any other, but what you need is to replace the HTML Entities by the correct characters...
You probably can find C# libraries that you can integrate, or even implement a simple routine to Search & Replace.

Try to find something in Forge to help you.

If I understood well, you are "translating" the XML to HTML through an action. you may adapt this routine to make the translation automatically...

Cheers.

Hi Eduardo,

The API response has encoded HTML inside XML (very weird) and I'm just pulling it out :(

But I got your point.

First I'll try out the Forge and if I couldn't find anything useful, I'll implement the simple routine you mentioned.

Thank you very much for your help!

PS

It isn't weird for XML to have encoded HTML inside. shame on me...


> If I understood well, you are "translating" the XML to HTML through an action. you may adapt this routine to make the translation automatically

this is completely right.