3

I would like to do this, have escape false...

<apex:outputText value="{!myUrlField}" escape="false"/>

...when I am using a bracketed call:

{!myUrlField}

Specifically, this is for writing META tags, for having sharing URLs that may contain ampersands.

When I do this:

<meta property="og:image" content="{!sharingImage}" />

An image URL with ampersands is HTMLEntity encoded, and the resulting salesforce image URL does not work. http://sierra.force.com/actions/servlet/rtaImage?eid=701i0000001Kz4q&feoid=00Ni000000FxwVD&refid=0EMi0000000Dh8N becomes http://sierra.force.com/actions/servlet/rtaImage?eid=701i0000001Kz4q&feoid=00Ni000000FxwVD&refid=0EMi0000000Dh8N Which does not work.

Open to having a better way to do this, I've tried replacing, but the encoding happens when it is written to the page.

Thanks for any ideas or info.

  • You'll need to encode the value using Apex (I'm not sure if you can use urlencode or if you'll need to do a custom replace). Then on the HTML page, do a decode using Javascript. – Caspar Harmer May 13 '15 at 1:15
  • Here's some more useful info about atob and btoa developer.mozilla.org/en-US/docs/Web/API/WindowBase64/… – Caspar Harmer May 13 '15 at 1:23
  • Javascript can use atob and btoa to encode and decode base64 strings. – Caspar Harmer May 13 '15 at 1:24
  • Actually for your issue, can't you just use EncodingUtils.urlencode(value)? – Caspar Harmer May 13 '15 at 1:27
  • hah, more questions - I don't get this problem - no url encoding happens for me. What does your <apex:page definition look like? – Caspar Harmer May 13 '15 at 1:45
0

You can set the value to a property in your controller. In your case "myTextField". Then set it as innerHTML from javascript/jQuery on page load. For example if in controller if you have set myTextField as below,

myTextField = '<h1>testing HTML content</h1>';

In the page you can use it like,

document.getElementById("yourPageElementIdHere").innerHTML('{myTextField}');
| improve this answer | |
  • So {!myTextField} is a field in a campaign, I don't need to set the value. The problem is that the value being set is transformed in a way that does not work for its application. – Adrian Cotter May 13 '15 at 17:16
0

The Answer is not to use the Value but to do it like this:

<apex:outputText escape="false">{!myUrlField}</apex:outputText>

When you write it as the value weird things happen for seemingly no reason.

| improve this answer | |
  • Thanks Cody Beaner, it still seems to write it out escape sadly. This: <apex:outputText escape="false"> <meta property="og:image" content="{!kw_SharingImage}" /> </apex:outputText> <apex:outputText escape="false" value="{!kw_SharingImage}"> </apex:outputText> Gives me: <meta content="http://knowwho-scaction.cs16.force.com/action/servlet/rtaImage?eid=701f000000045eL&amp;feoid=00Nf00000013HM5&amp;refid=0EMf0000000ChW4" property="og:image" /> http://knowwho-scaction.cs16.force.com/action/servlet/rtaImage?eid=701f000000045eL&feoid=00Nf00000013HM5&refid=0EMf0000000ChW4 – Adrian Cotter May 13 '15 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.