interpolate
Utility to use javascript template literal syntax in custom labels
Import
Section titled “Import” import { interpolate } from 'c/boltage';import greeting from "@salesforce/label/c.greeting"; // => Hello ${name}export default class myLwc extends LightningElement { connectedCallback() { console.log(interpolate(greeting, { name: "Theo" })) }}Methods
Section titled “Methods”interpolate(label, params) : string
Section titled “interpolate(label, params) : string”| Name | Type | Description |
|---|---|---|
label | string | Label reference in teh format of a template literal string |
params | Object | Key/Value pairs to be templated inside the label |
interpolate(label) : withValuesFrom(source) => string
Section titled “interpolate(label) : withValuesFrom(source) => string”| Name | Type | Description |
|---|---|---|
label | string | Label reference in teh format of a template literal string |
source | Object | Object containing the key/value pairs to be templated inside the label |
import greeting from "@salesforce/label/c.greeting"; // => Hello ${Name}export default class myLwc extends LightningElement { connectedCallback() { const contact = { id: "XXXX", Name: 'John Doe', foo__c: 'bar' } console.log( interpolate(greeting) .withValuesFrom(contact) ); }}