1

I am trying to substitute multiple substrings in a value on a visualforce page. I tried using nested SUBSTITUTE() functions, but I get an error message "The element type "p" must be terminated by the matching end-tag "

"."

<p class="product-name">
    {!SUBSTITUTE(SUBSTITUTE(p.Product2.Short_Product_Description__c, "{", "<sup>"),"}", "</sup>")}
</p>

Note: I am able to do a single substring substitution with a single SUBSTITUTE() call like so:

<p class="product-name">
    {!SUBSTITUTE(p.Product2.Short_Product_Description__c, "{", "<sup>")}
</p>

However this is undesirable as I also need to substitute the "}" character with a "</sup>"

2 Answers 2

1

This is the solution I found that works:

<apex:outputText value="{!
    SUBSTITUTE(
        SUBSTITUTE(p.Product2.Short_Product_Description__c, '[', '<sup>'),
        ']', '</sup>'
    )
}" escape="false"/>

The curly braces are what was triggering it and an with escape attribute set to false is required to render the html properly

0

You should be able to use nested SUBSTITUTE functions like your first example. Though I think your problem is elsewhere - there must be another piece of unescaped HTML in your string which is conflicting with the parent <p> tag. I strongly suggest using HTMLENCODE in conjunction when you're outputting text which may contain HTML code:

{!HTMLENCODE(SUBSTITUTE(SUBSTITUTE(p.Product2.Short_Product_Description__c, "{", "<sup>"), "}", "</sup>"))}

8
  • Hi Boris, there is no HTML in the string whatsoever. It contains only alphanumeric characters and one instance of "{" and "}", respectively. The error does not occur with the single SUBSTITUTE() call. I tried wrapping the entire thing in HTMLENCODE() as you suggested and still get the error
    – ag415
    Commented Oct 26, 2017 at 0:49
  • 1
    Unfortunately, it looks like with or without HTMLENCODE(), my tags are not rendered properly in the VF page. They appear either as plain text or as "&lt;" and "&gt;". Guess its back to the drawing board...
    – ag415
    Commented Oct 26, 2017 at 1:04
  • 1
    Glad to hear you sorted it out! Commented Oct 26, 2017 at 1:06
  • 1
    It looks like if I insert this entire formula into an <apex:outPutText> value attribute and set the escape attribute to "false" I can render the HTML correctly
    – ag415
    Commented Oct 26, 2017 at 1:08
  • 1
    Post it as an answer :) Commented Oct 26, 2017 at 1:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .