Output dynamically generated HTML in Jelly

October 21, 2014

Tags: ServiceNow Jelly HTML

It can be a pain trying to output some HTML stored within a variable using Jelly. When printing an expression with Jelly, it is automatically escaped.

For example

<g:evaluate var="jvar_some_content">
  var content = "<p>foo</p><p>bar</p>";
  content;
</g:evaluate>
<div>${jvar_some_content}</div>

Will output:

<p>foo</p><p>bar</p>

To prevent Jelly from escaping the output, using no_escape as follows:

<g:evaluate var="jvar_some_content">
  var content = "<p>foo</p><p>bar</p>";
  content;
</g:evaluate>
<g2:no_escape>${HTML:jvar_some_content}</g2:no_escape>

Will output:

foo
bar

Comments

comments powered by Disqus