Hello All,
Today we will disscus, how to use custom label into Lighting web componet (LWC).
Sample steps,we will follow below steps for that
1.Create custom labels
To create custom labels, from Setup, enter Custom Labels in the Quick Find box, then select Custom Labels. Here are the custom labels created. we will see how to use the lightning web components
labelName—A name that refers to the label.
labelReference—The name of the label in your org in the format namespace.labelName
Sample Code:-
// labelExample.js
import { LightningElement } from 'lwc';
// Import the URL for the static resource named 'salesforceLogo'
import SALESFORCE_LOGO from '@salesforce/resourceUrl/salesforceLogo';
// Import custom labels
import greeting from '@salesforce/label/c.greeting';
import salesforceLogoDescription from '@salesforce/label/c.salesforceLogoDescription';
export default class LabelExample extends LightningElement {
// Expose the static resource URL to use in the template.
logoUrl = SALESFORCE_LOGO;
// Expose the labels to use in the template.
label = {
greeting,
salesforceLogoDescription,
};
}
<!-- labelExample.html -->
<template>
<c-page-header header="Using static resources and custom labels" description="This sample shows how to reference external items like static resources and custom labels"></c-page-header>
<c-card>
<img src={logoUrl} alt={label.salesforceLogoDescription} width=100><br>
<br>
{label.greeting}
</c-card>
</template>
For more detail :-Please visit salesforce site:-Access Labels
Today we will disscus, how to use custom label into Lighting web componet (LWC).
Sample steps,we will follow below steps for that
1.Create custom labels
To create custom labels, from Setup, enter Custom Labels in the Quick Find box, then select Custom Labels. Here are the custom labels created. we will see how to use the lightning web components
2.Use Custom Labels in LWC
import labelName from '@salesforce/label/labelReference';labelName—A name that refers to the label.
labelReference—The name of the label in your org in the format namespace.labelName
Sample Code:-
// labelExample.js
import { LightningElement } from 'lwc';
// Import the URL for the static resource named 'salesforceLogo'
import SALESFORCE_LOGO from '@salesforce/resourceUrl/salesforceLogo';
// Import custom labels
import greeting from '@salesforce/label/c.greeting';
import salesforceLogoDescription from '@salesforce/label/c.salesforceLogoDescription';
export default class LabelExample extends LightningElement {
// Expose the static resource URL to use in the template.
logoUrl = SALESFORCE_LOGO;
// Expose the labels to use in the template.
label = {
greeting,
salesforceLogoDescription,
};
}
<!-- labelExample.html -->
<template>
<c-page-header header="Using static resources and custom labels" description="This sample shows how to reference external items like static resources and custom labels"></c-page-header>
<c-card>
<img src={logoUrl} alt={label.salesforceLogoDescription} width=100><br>
<br>
{label.greeting}
</c-card>
</template>
For more detail :-Please visit salesforce site:-Access Labels
No comments:
Post a Comment