External, inline links in Ephox

I have an external link content type that I’m adding into the “body” field of various content items (I’m using the Ephox “Insert Rhytmyx Template” control). This works great until I have an ampersand in the url, and it seems that ephox performs it’s magic html optimization and converts it to “& amp;” thus breaking the url. Is there a way to add an exception for that specific field?

Using something like this $rx.codec.decodeFromXml(rx:fieldname) should work. this should keep it from encoding the URL

Thanks for the response. It didn’t appear to work, though. This is what I have:


#set($url=$rx.codec.decodeFromXML(rx:url))
[a href="$url"  alt="#displayfield('displaytitle')"]#displayfield("displaytitle")[/a]


I also tried adding “$url” to the bindings.

sorry that class is expecting a string so you probably need to do something like this:

$rx.codec.decodeFromXml($sys.item.getProperty(“externalink”).String))

Sorry that syntax is a little wrong it should be something like the following:

$rx.codec.decodeFromXml($sys.item.getProperty(“rx:url”).String)

I just tried that in a binding using the rffsnTitelink I then created an external link with an & in the url then insert this link inline to the body of a generic content type and the & was in tact.

Hi Nick,

I’m just now getting back to this issue. I’m still having trouble with ampersands in my url, even using this format: $rx.codec.decodeFromXml($sys.item.getProperty(“externalink”).String))

This is the error that appears:

Error processing inline link Problem while processing inline link for item 2-101-4916: The reference to entity “en” must end with the ‘;’ delimiter. See the replacement body in the console log. The attributes on the affected link were: alt=“Mentee Information Form”,class=“inline newwin”,contenteditable=“false”,href=“http://www.kintera.org/AutoGen/Contact/ContactUs.asp?ievent=283265&en=klIQK4OQLjITI5MTJdLOLbPWKpL9LhPPKjL1I9NULpJWIdP5IzE",inlinetype=“rxvariant”,rxinlineslot=“105”,rxselectedtext=“<a%20href%3D"http%3A%2F%2Fwww.kintera.org%2FAutoGen%2FContact%2FContactUs.asp%3Fievent%3D283265%26%2338%3Ben%3DklIQK4OQLjITI5MTJdLOLbPWKpL9LhPPKjL1I9NULpJWIdP5IzE”>Mentee%20Information%20Form<%2Fa><br%20%2F> “,sys_dependentid=“4927”,sys_dependentvariantid=“1198”,sys_folderid=”“,sys_relationshipid=“18997”,sys_siteid=”“,target=”_blank",title="Mentee Information Form”

Hey Brad,

Could you try setting the result of the call to the externallink property into a variable and outputing that to the screen. This way you may be able to see what it is trying to do to the url.

I did just that, and the url appears ok, but only when I view it with the specific snippet template. There are some quirky things going on here, so I think I will submit a support ticket and have you folks take a look.

thats fine submit a ticket and we can take a look

Thanks for your help, Nick (via Percussion support).

Here’s the correct syntax, in case anybody comes across thread with the same issues:

#set($url=$rx.codec.escapeForXml($sys.item.getProperty(“rx:url”).String))

Using the “escapeForXml” function instead of the “decodeForXml” function.

It works beautifully.

For any field whose value contains an ampersand, you will encounter an error if the field is rendered by a template inserted inline into an EditLive (Ephox) field.
For code re-use, you can just create macro functions that escape such characters, and use them in your template to render the field when needed:
Open Workbench > System Design > expand Configurations > Open User Velocity Macros (rx_Assembly.vm)> Add the following code to the bottom of the file and save:


#macro(fieldEsc $fieldname)##
#startAAField($fieldname "")##
#if ($sys.part.render)##
$rx.codec.escapeForXml($sys.item.getProperty($fieldname).String)##
#end#endAAField($fieldname)##
#end##

#macro(fieldLinkEsc $fieldname $pagelink)## #startAAField($fieldname
$pagelink)## #if ($sys.part.render)##
$rx.codec.escapeForXml($sys.item.getProperty($fieldname).String)##
#end##
#endAAField($fieldname)##
#end##

#macro(displayfieldEsc $fieldname)##
$rx.codec.escapeForXml($sys.item.getProperty($fieldname).String)##
#end##

#macro(field_if_set_esc $before $field $after)##
#if($sys.item.hasProperty($field))##
$before##
#fieldEsc($field)##
$after##
#else##
#__handlefieldaa($field)##
#end##
#end

I prefer to use $tools.esc.html($sys.item.getProp erty(“rx:url”).String) some XML entity’s are not rendered in html an example is apos which is valid in xml but not html.

I think it does depend on which version of velocity tools you have if $tools.esc.html is available