Displaying HTML with Jelly in a UI page

jdurden
Kilo Explorer

So, I went into this project thinking this was going to be pretty straight forward. And, maybe it is. But what I thought should work intuitively isn't working as I anticipated and the information I'm finding online isn't working.

What I'm trying to do is display some HTML (on a UI Page) which is stored in a variable. Example...



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate>
var test = "<b>this is bold</b>";
</g:evaluate>

${test}
</j:jelly>


In case it's not clear, the desired outcome is to have a simple bold text "this is bold" display on the UI Page when visited. However, when you visit the page it looks like:

<b>this is bold</b>


Clearly the HTML is being encoded at some point in this whole thing and, despite searching forums and Google, I'm unsure how to fix it. Any ideas?


Thanks in advance!

25 REPLIES 25

If you are satisfied with my response,are aren't looking for another interpretation , please mark this as answered.. This will help the other community members to concentrate on those questions which need reponses.

Thanks!


Without the need of an intermediate input, but almost the same.



<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<g:evaluate var="jvar_str">
test = "<b>Bold</b>";
</g:evaluate>
<div>
<script>
document.write('${jvar_str}');
</script>
</div>
</j:jelly>


pu
Giga Contributor

Stumbled across this thread when looking for a solution but have since found an easier way that works for me.

I'm doing a Glide query to get the data from an HTML field and need to output it as HTML to a UI page.

There is a ready made Jelly tag to do the escaping / decoding for you it seems:


<g2:no_escape>$[gr.myHTMLField.getDisplayValue()]</g2:no_escape>


Thanks Paul, this definitely is a better way of doing it.

Also, the reason why I had to show the solution the way I did, is because I had to explain why the code given doesn't work 🙂


Jertay
Tera Contributor

"no_escape" seems super ominous, but it worked for me, so thanks!