Skip to content

interpolate

Utility to use javascript template literal syntax in custom labels

Import

import { interpolate } from 'c/bolt';

Usage

import greeting from "@salesforce/label/c.greeting"; // => Hello ${name}
export default class myLwc extends LightningElement {
connectedCallback() {
console.log(interpolate(greeting, {
name: "Theo"
}))
}
}

Methods

interpolate(label, params) : string

NameTypeDescription
labelstringLabel reference in teh format of a template literal string
paramsObjectKey/Value pairs to be templated inside the label

interpolate(label) : withValuesFrom(source) => string

NameTypeDescription
labelstringLabel reference in teh format of a template literal string
sourceObjectObject 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)
);
}
}