Christopher_Mal
ServiceNow Employee
ServiceNow Employee

Whenever I get a question about Jelly I start to sweat nervously. Then you throw in a question about phase 1 and phase 2 idiosyncrasies and I start to mumble like a crazy person.   So, here's a little story I've got to tell - </end-beastie-boy-impression>

Stephan Nolan, an employee working with me at RMIT, asked the question:

"We have a dynamic content block with the following:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
        <h1>Hello World</h1>

        <script id="template" type="text/x-handlebars-template">
                <![CDATA[
                        <label>
                                <input
                                        name="example"
                                        type="radio"
                                        value="1"
                                        {{#if blah}}checked="checked"{{/if}}
                            />
                                <span>Radio button</span>
                        </label>
                ]]>
        </script>
</j:jelly>

Which works fine when two phase is turned off.   However when we turn it on, the <![CDATA[]]> tags are being ignored and the following error is thrown

Element type "input" must be followed by either attribute specifications, ">" or "/>".: org.xml.sax.SAXParseException: Element type "input" must be followed by either attribute specifications, ">" or "/>".:

We need two phase turned on to enable HTML escaping.   Currently our only solution is to replace the '<' of the input with &lt; to bypass jelly parsing."

I couldn't figure out a nice an simple answer for him on this, but much to my delight he figured out a nice solution later on and shared the fact that if you have this requirement, wrap your script in a UI Macro and use an inline template. Example <g2:inline template="uimacro.xml".   It looks like the first phase eats up the CDATA tags and when we go into phase two we get the above error.   If we inline in the second phase we get to keep the CDATA tag and there is no need to escape all those pesky < > brackets.   Thanks Stephen for the tip.   I hope it helps someone else out there in Jelly hell, I mean land.  

Extensions to Jelly Syntax - ServiceNow Wiki

5 Comments