Get variable value

variable.get(options?)

Retrieves the value of the variable.

Syntax

variable.get(
options?: {
mode: VariableMode,
customValues: boolean,
doNotInheritFromBase: boolean}
): Promise<string | number | SizeValue | Variable | CustomValue>;

Parameters

  • options: object - An optional parameter to include get specific information.

    ParameterTypeDescriptionDefault
    modeVariableModeThe value of the variable in the specified variable mode.
    customValuesbooleanIndicates whether to return the custom value of the variable.false
    doNotInheritFromBasebooleanIndicates whether to return the value of the variable without inheriting from the base variable mode.false

    Calling variable.get() without customValues: true will throw an error if the variable has a custom value.

Returns

Returns a Promise that resolves to the current value of the variable. The exact return type depends on the variable’s type, whether it’s an alias or a custom value, and the selected variable mode.

See the table below for details on return types for each scenario.


Returns a value in one of these formats:

FormatExamplesReturn Type
String"red", "#ffcc11", "#fffcc11"string
Variable alias{ "id": "variable-xyz-123" }ColorVariable
Custom value{"type":"custom","value":"color-mix(in srgb, var(--blue-500) , #fff 60%)"}CustomValue

Example

// Get Collection
const collection = await webflow.getDefaultVariableCollection();
// Get All Variables
const variables = await collection.getAllVariables();
// Get Value of first Variable
const variable = variables[0];
const value = await variable.get();
// value = "#146EF5"
// Get Value of first Variable with custom value
const variable = variables[1];
const value = await variable.get({ customValues: true });
// value = { type: 'custom', value: 'color-mix(in srgb, var(--blue-500), white 50%)' }

Designer ability

Checks for Authorization only

Designer abilityLocaleBranchWorkflowSitemode
canReadVariablesAnyAnyAnyAny