Skip to content

replaceVariables

replaceVariables(content, mappings, defaultValue?): string

Replace tokens in a string of {{ TYPE.VARIABLE }} with the value found in the mappings object with the structure of:

{
type1: {
variable1: 'value1',
variable2: 'value2'
},
type2: {
variable1: 'value3',
variable2: 'value4'
}
}

With the above structure, the template of The value of type1, variable1 is {{ type1.variable1 }} would be translated into: The value of type1, variable1 is value1

Parameters

content: string

Any string containing variables that will be replaced by the defined mappings

mappings: VariableMappings

A collection of type to value mappings that will be used to replace matched variables

defaultValue?: string

The value to use if no match is found. Defaults to ”.

Returns

string

Defined in

@meltmedia/totem/lib/config/variables.d.ts:30