How to use Custom Labels In Lightning Web Component(LWC)

by Rijwan Mohmmed
0 comment
How to use Custom Labels In Lightning Web Component(LWC)

Custom labels are simple text values that can be accessed from LWC Component, Aura Component, Apex classes, Visualforce pages.

Create Custom Labels :

Go To Setup —>Create — >Custom Labels.
Click on New Custom Labels.Enter value for name, value, and description.

Use Custom Label in LWC Component :

We can get custom label value by import a label in a Lightning Web Component JavaScript file, use @salesforce/label .

import labelName from '@salesforce/label/labelReference';
  1. labelName — A name that refers to the label in LWC JS File.
  2. labelReference — The name of the label in your org in the format namespace.labelName. if no namespace then you can use labelName.

techdicerLabel.js

import { LightningElement } from 'lwc';
//Import custom labels
import techdicertes1 from '@salesforce/label/c.techdicertes1';
import greeting  from '@salesforce/label/c.greeting ';

export default class LabelExample extends LightningElement {
    // Expose the labels to use in the template.
    label = {
        greeting,
        techdicertes1,
    };
}

techdicerLabel.html :

<template>
        <p>{label.greeting}</p>
        <p>{label.techdicertes1}</p>
</template>

Reference : https://developer.salesforce.com/docs/component-library/documentation/en/lwc/create_labels

What’s your Reaction?
+1
2
+1
1
+1
0
+1
0
+1
0
+1
0

You may also like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.