Is there an easy way to show a multi-line Custom Label in a Visualforce page with the line breaks working correctly?
You can achieve it via:-
Apex :- replace newline character by html line break (< br/>) and use the resultant string value to display on page
String displayValue = System.label.label_name.replace('\n','
');Javascript :- Use javascript to replace newline character by html line break
< div id="testDiv" > < /div>
<script>
var val = '{!JSENCODE($Label.test_label)}';
val = val.replace(/\n/g,'<br\>');
document.getElementById('testDiv').innerHTML = val; //for testing purposes
</script>
This is something which cannot be achieved by purely using custom labels. Any line breaks in the custom label is lost and the text is displayed as a single line on VF page.
This is what I do.
Split the string with any random character.
If the custom label is 'This is Line One. This is Line Two', I will change it to 'This is Line One. 555 This is Line Two'.
Replace '555' with any random character that you find it easy to remember.
String s = Label.YourLabelName;
List<String> l = s.split('555');
l[0] will contain the first sentence and l[1] will contain the second sentence. Use this list on VF page.