[SalesForce] Inserting HTML Markup in Custom Label Value

I'm using Custom Labels for a specific message and I'd like to insert a link into that message, e.g., <a href="http://my.domain.com">Go here to login</a>.

I tried this using entity characters for rending the HTML, but that just renders it as a full string:

<CustomLabels>
    <labels>
        <fullName>Legal_Disclaimer_Text</fullName>
        <language>en_US</language>
        <protected>true</protected>
        <shortDescription>Legal_Disclaimer_Text</shortDescription>
        <value>You must agree to the terms of use and privacy notice below. &lt;a href='http://my.domain.com'&gt;Go here to login&lt;/a&gt;</value>
    </labels>
</CustomLabels>

Can HTML markup be added to Custom Labels?

Best Answer

In Aura, you can do this via aura:unescapedHtml. This will render the text as is. Obviously, make sure you don't allow any unsafe HTML in there, because it could be a security risk. As long as the text is static, this is probably acceptable.

<aura:unescapedHtml value="{!$Label.c.Legal_Disclaimer_Text}" />

In general, you can have HTML in labels, but most language features (e.g. Visualforce) will take steps to automatically encode HTML as HTML entities to avoid injection attacks. Developers must always take specific actions in order to override this behavior.

Related Topic