Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Preserving Whitespace Jelly script

adam_webster
Kilo Contributor

Hi,

I'm working on a dynamic content block and im struggling on preserving the white space.

I want to maintain the white space between the apostrophes: news   += ('             ')

Any suggestions?

Script:

<?xml version="1.0" encoding="utf-8" ?>

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

  <j2:whitespace trim="false">

  <span style="color:red">

    <g:evaluate>

        var news = '' ;

      var kb = new GlideRecord('kb_knowledge');

      var now = gs.dateGenerate(gs.yesterday(), 'end');

      kb.addQuery('valid_to', '>', now);

      kb.addQuery('topic','News');

  kb.addQuery('category', 'NewsFlash');

      kb.addQuery('workflow_state','published');

      kb.query();

  while (kb.next()){

  (news == '') ? news = kb.short_description.toString()   : news   += ('             ')   + kb.short_description.toString();

}

  </g:evaluate>

<j:while test="${kb.next()}">

<j:if test="${kb.canRead()}">

     

  <g:evaluate>

  news +=   kb.short_description + ('                   ');

 

  </g:evaluate>

</j:if>

</j:while>

  <marquee behavior="scroll" direction="left"><b>${news} </b></marquee>

  </span>

  </j2:whitespace>

</j:jelly>

Thanks,

Adam

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee

I always have a good bit of trouble with jelly stripping out white spacing event when using ${SP}. What I usually do is use a div with a margin to add the space. So something like:



<marquee behavior="scroll" direction="left"><div style="font-weight:bold;margin-right:10px">${news}</div></marquee>


View solution in original post

9 REPLIES 9

K10
Kilo Guru

Hi Adam,



You can use ${AMP} to insert an ampersand in Jelly.You may want to refer below link. This will help.



Extensions to Jelly Syntax - ServiceNow Wiki


adam_webster
Kilo Contributor

Hi Ketan,



Thanks for your suggestion using the ${AMP}   I just get the value &.



how and where should I use the ${AMP}?




Thanks,



A


Brad Tilton
ServiceNow Employee

I always have a good bit of trouble with jelly stripping out white spacing event when using ${SP}. What I usually do is use a div with a margin to add the space. So something like:



<marquee behavior="scroll" direction="left"><div style="font-weight:bold;margin-right:10px">${news}</div></marquee>


Hi Brad,



Many Thanks for your solution.