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

Ximizu
Mega Guru

Hi John,



Another example which works:


use <g2:no_escape> tag and prefix your JEXL expression with HTML




Code:


<g:evaluate var="jvar_myvar">


  var myText = "this is <b>bold</b>";


  myText;


</g:evaluate>



<g2:no_escape>${HTML:jvar_myvar}</g2:no_escape>



Output:


this is bold




Before it works, I had first tried to follow the instruction of this wiki page but it didn't work. They are not mentioning <g2:no_escape> tag.


Thanks to Paul Urquhart's comment, I did some test mixing the <g2:no_escape> tag and HTML prefix until finding this solution.



Regards,



Ximizu


noahstahl
Giga Contributor

Curious if anyone has tried these techniques in Fuji or Geneva? I'm not able to get the value to be treated as HTML, always raw markup is displayed.


Yea, I'm using right on a function I'm building in geneva. Well, to be exact Im not using the jvar, but I doubt that will have any different, here come part of the code so you can see for yourself what I mean.



<g:evaluate>


  if (RP.getWindowProperties().get('number')) {


  var artnum = RP.getWindowProperties().get('number');


  }


  else {


  var artnum = gs.getProperty('custom.newfeature.kbdocument');


  }


  var article = new GlideRecord('kb_knowledge');


  article.get('number', artnum);



</g:evaluate>




<div id="info">


  <h1> ${article.short_description}</h1>


  <g:no_escape>${HTML:article.u_featureinfo}</g:no_escape>  


Thanks Goran, this got me to a working solution. In particular, two things to note for others looking to do something similar:


- Use "g", not "g2" prefix for the no_escape element


- Getting the value via RP.getWindowProperties().get("<glide dialog window preference key>") did not work and would result in raw HTML. Getting the same value via a GlideRecord call and reading its property does work.


Strange the RP.getWindow.... don't work for you. or do you mean that you tried to send HTML with a glideDialogWindow preference and fetch it with the RP...?