0

I have below data stored in a rich text are field.

<html><head></head><body>Hello</body></html>

Controller

public with sharing class ContentController {
    public List<Content__c> contentList {get;set;} 
    public ContentController() {
        getContent();
    }
    private void getContent() {
        ContentList = [SELECT Id,HTMLContent__c,
                               FROM Content__c LIMIT 2];
    }
}

Page

<apex:outputText value="{!ContentList[0].Content__c}">
    escape="false"
</apex:outputText>

But when i render data in the page it is not displaying content, rather it is displaying html as a text. "<html><head></head><body>Hello</body></html>" Can anyone help me with this?

  • I tried to reproduce it, but it worked and rendered my hello. The only issues I had were problems you probably introduced when you wrote the question. Please consider editing your question to fix these errors, it won't compile like this! {!ContentList[0].Content__c} should be {!ContentList[0].HTMLContent__c} - there also is a comma too much in your SOQL , FROM Content__c and your escape="false" should be within the tag. Since I could not reproduce it, please provide more details about your problem. – Basti Dec 4 '17 at 17:13
2

This should work. For some reason you are doing the escape="false" at the wrong place

<apex:outputText value="{!ContentList[0].HTMLContent__c}" escape="false" />
  • I am using escape="false" within tag only, somehow it was not given properly here. But still i am not able to get the html content – Chaithra K N Dec 4 '17 at 16:23
  • I'm not sure about this, the code does not change when you copy it here. I fixed the formatting of your post and saw, that the escape attribute was in the same line, but behind the tag: <apex:outputText value="{!ContentList[0].Content__c}"> escape="false" – Basti Dec 4 '17 at 16:40
  • But it is correctly given in my codebase, still it is not rendering – Chaithra K N Dec 4 '17 at 16:46
  • Hm okay, are you sure it is not escaped in your field already? – Basti Dec 4 '17 at 16:58
  • In the fields it is stored like below, <html><head></head><body>Hello</body></html> – Chaithra K N Dec 4 '17 at 17:00

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.