Play Games

Search This Blog

Saturday, June 4, 2022

use custom label in Lightning Web Component - Salesforce Globe For You

use custom label in Lightning Web Component - Salesforce Globe For You

Solution: first import the label using @salesforce/label/c.labelname and assign to a variable and use that variable in html file

import blogUrl from '@salesforce/label/c.Blog_URL';

customLabelRef = blogUrl;

{customLabelRef}

Example:

customLabelInLWC.html

<template>

    <lightning-card title="Custom Label In Lightning Web Component">

       Custom Label :  {customLabelRef}

    </lightning-card>

</template>

customLabelInLWC.js:

import { LightningElement } from 'lwc';

import blogUrl from '@salesforce/label/c.Blog_URL';

export default class CustomLabelInLWC extends LightningElement {

    customLabelRef = blogUrl;

}

customLabelInLWC.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

    <apiVersion>52.0</apiVersion>

    <isExposed>true</isExposed>

    <targets>

        <target>lightning__AppPage</target>

        <target>lightning__RecordPage</target>

        <target>lightning__HomePage</target>

    </targets>

</LightningComponentBundle>

Output:



No comments:

Post a Comment