0

In our scenario, I need to display a list of text in our Visualforce page. Some part of the text needs to be bold. I will explain this with the below simple but not working example:

page:

<apex:page controller="TestListOutputController">
    <apex:repeat var="ot" value="{!outText}" >
        <div>
            {!ot}
        </div>
    </apex:repeat>
</apex:page>

controller:

public class TestListOutputController 
{
    public List<String> outText {get; set;}
    public TestListOutputController()
    {
        outText = new List<String>();
        outText.add('Hello <Strong>World</Strong>');
        outText.add('Sample <Strong>Text</Strong>');
    }
}

Obviously the strong tag here doesn't work. I can walk around this if the number of bold blocks is fixed. However, what if it is something like a blog section, or a stackexchange answer section? How should I handle such situations?

2
1

If you want to enable markup, use an <apex:outputText> with the escape attribute set to false.

<apex:outputText escape="false" value="Hello <strong>world</strong>!" />

Be aware, though, that if you are trying to use this attribute in a managed package, it will likely cause you to fail security review.

2
  • How about using RichText directly.? Mar 9 '17 at 5:10
  • @RohitMourya Not sure what you're getting at in relation to <apex:outputText>?
    – Adrian Larson
    Mar 9 '17 at 5:13
1

You could use the Visualforce component <apex:outputText> and set the escape attribute to false.

<apex:page controller="TestListOutputController">
    <apex:repeat var="ot" value="{!outText}" >
        <apex:outputText escape="false" value="{!ot}" />
    </apex:repeat>
</apex:page>
2
  • Both answers are just equally awesome and I have to use order by who answers first to get the accepted answer. Thanks for your input though. It is really helpful.
    – Lance Shi
    Mar 9 '17 at 5:56
  • Sounds fair to me. I'm glad I could help.
    – martin
    Mar 9 '17 at 5:59

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.