function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SalesRedSalesRed 

How to add a HTML break in a Custom Label

Hi,

 

I'm using custom labels on my visualforce page.  This generally works ok however in a popup screen I have when the custom label is long the apex:pagemessage displays funny (the severity icon is overlapped with the text(.  I was thinking that I could get around this by adding line breaks into the Custom Label but a <br> tag cannot be added when creating a custom label.  Does anyone know if there is a way to do something like this?  I know &nbsp; can be used to add spaces.  For a line break is there a similar non <br> tag which cab be used?  Or is there a way of escaping the <br> when I try to add it to the custom label?

 

Thanks in advance for any suggestions.

Best Answer chosen by Admin (Salesforce Developers) 
HariDineshHariDinesh

Hi,

You can try from user interface Custom Labels,then you will not face this issue.

 

ok anyway

Now you can try like below syntax. it is working fine.

 

<labels>
        <fullName>test_label</fullName>
        <language>en_US</language>
        <protected>false</protected>
        <shortDescription>test label</shortDescription>
        <value>This is &lt;/br&gt; Test Label111 &lt;br&gt; second Line</value>
 </labels> 

 

All Answers

HariDineshHariDinesh

Hi,

 

There is a way for this

 

I am giving an example for custom Label for this:

 

EX:  point 1'+'\n'+'point 2'+'\n'+'point3

 

In the value of custom Label give like as above(modify accordingly)

 

Now in UI it will be displayed like below 

 

Point 1

Point 2

Point 3

 

Is this resolves your problem or you are looking for some other..

Let me know..

SalesRedSalesRed

Hi HariDinesh,

 

Thank you for your help/suggestion.  I've tried this out and the \n actually displays in my apex:pageMessages in which the custom label is displayed instead of adding a HTML line break.  I've tried escape="false" in my apex:pageMessages tag also

 

<apex:pageMessages escape="false"/>

 

Do you know if I need to add another change to make it to work?

 

Thanks again.

HariDineshHariDinesh

Ok,

 

Yes, It works for showing labels in Java script Alert messages, might not suit for you.

 

As you specified in first post For <apex: pageMessage component the below code will be works

 

<apex:page>
<apex:form>
  <apex:pageBlock>
    <apex:pageMessage title="{!$label.test_label}"  severity="error" escape="false"/>
  </apex:pageBlock>
  </apex:form>
</apex:page>

Label content like this This is </br> test label.

 

Now for showing message in <apex:pageMessages like you expected try below

 

VFP:

<apex:page controller="testlable" cache="true">
    
    <apex:form id="frmid" >
      <apex:outputPanel id="op">
        <apex:pagemessages id="pgMsg" escape="false" ></apex:pagemessages>
      </apex:outputPanel>
            
      <apex:PageBlock >
        <apex:PageBlockSection columns="1">
          <apex:commandButton value="back butt" action="{!backToList}"/>
        </apex:PageBlockSection>   
      </apex:PageBlock>
        
    </apex:form>
     
</apex:page>

 Apex Class

Public class testlable
{
   public PageReference backToList()
            {
               ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.ERROR, Label.test_label));
                return null;
            }
}

 Custom Label: This is </br> Test Label <br> second Line

SalesRedSalesRed

Hi HariDinesh,  Thanks for your suggestions.  I think the main problem though lies in that I cannot save the Custom Label if using <br>'s

 

if I try

 

<labels>
<fullName>PasswordSuccessMessage</fullName>
<language>en_US</language>
<protected>true</protected>
<shortDescription>ApexPage Message On Successful Password Reset</shortDescription>
<value>This is </br> Test Label <br> second Line</value>
</labels>

 

I get 

Description Resource Path Location Type
Save error: CustomLabels : Error parsing file: The element type "value" must be terminated by the matching end-tag "</value>". CustomLabels.labels /TestWebSites/src/labels line 288 Force.com save problem

 

 

If I try
<labels>
<fullName>PasswordSuccessMessage</fullName>
<language>en_US</language>
<protected>true</protected>
<shortDescription>ApexPage Message On Successful Password Reset</shortDescription>
<value>This is </br> Test Label </br> second Line</value>
</labels>

 

I get


Description Resource Path Location Type
Save error: CustomLabels : Error parsing file: Unexpected element {http://soap.sforce.com/2006/04/metadata}br during simple type deserialization CustomLabels.labels /TestWebSites/src/labels line 288 Force.com save problem

 

Do you know if the break can be added & saved in the custom label?

 

Thanks again for all your suggestions :)

HariDineshHariDinesh

Hi,

You can try from user interface Custom Labels,then you will not face this issue.

 

ok anyway

Now you can try like below syntax. it is working fine.

 

<labels>
        <fullName>test_label</fullName>
        <language>en_US</language>
        <protected>false</protected>
        <shortDescription>test label</shortDescription>
        <value>This is &lt;/br&gt; Test Label111 &lt;br&gt; second Line</value>
 </labels> 

 

This was selected as the best answer
SalesRedSalesRed

Hi HariDinesh.

 

Thank you for your help.  Adding "This is &lt;/br&gt; Test Label111 &lt;br&gt; second Line"  works perfectly.  

 

Much appreciated. it works like a charm!

JamieSmithJamieSmith
We used this before. After creating a custom label like: 
<h3>Title</h3>
<hr />
<p style="color:blue;">This is a paragraph in blue</p>
You should be able to use something like this in your VF page: 
<apex:outputText  escape="false"  value="{!$Label.yourLabelName}" />
or using HTML tags like: 
<apex:outputText  escape="false"  value="<strong>{!$Label.yourLabelName}</strong>" />