Access custom labels in lightning web component

To access custom labels in lwc, we have to import from @salesforce/label scoped module.

For Example in Js you have to import the custom label as given below and expose the label for use in html templates :-

So In this example i created a custom label in salesforce to store the url which will be used in lwc component as link in one scenario. so if in any case that we have to make changes to the link url in production it would be easy if we stored that url in custom label(Hard coding the url directly in lwc is not a best practice).

import service_code_url from '@salesforce/label/c.Service_code_url'

label = {
service_code_url}; 

imported custom label from js file usage in html template:-

<a title="When Can I provide a Service Code?"
href={label.service_code_url}
target="_blank">When can I provide a Service Code? </a> 

Syntax :-

import labelName from '@salesforce/label/labelReference'

    Be the first to comment

    Leave a Reply

    Your email address will not be published.


    *