Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VisualForce: convert carriage returns to html line-breaks in a long text field

In Salesforce, if I'm binding a text field into a VisualForce page, whats a good way to convert the carriage returns in the text-field into HTML <br/> tags?

e.g. starting from something like this:

<apex:page standardController="Case">
  <apex:pageBlock title="Test">
      <p>{!case.Description}</p>
  </apex:pageBlock>                   
  <apex:detail relatedList="false" />
</apex:page>   

... if the Description is long with lots of carriage returns, how do I HTML-ify it?

(I guess this is a fairly easy question, and I'm sure I could google it, but to get the Salesforce community going on here I figure we need a few easy questions.)

edit: (Bounty added to try and generate some excitement)

like image 815
codeulike Avatar asked Mar 26 '10 18:03

codeulike


1 Answers

Try this:

<apex:outputField value="{!case.Description}"/>

Using output fields will maintain formatting automagically.

like image 198
TehNrd Avatar answered Sep 23 '22 15:09

TehNrd