Get variable value

variable.get(options?)

Retrieves the value of the variable.

Syntax

1variable.get(
2 options?: {
3 mode: VariableMode,
4 customValues: boolean,
5 doNotInheritFromBase: boolean}
6): 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

1// Get Collection
2const collection = await webflow.getDefaultVariableCollection();
3
4// Get All Variables
5const variables = await collection.getAllVariables();
6
7// Get Value of first Variable
8const variable = variables[0];
9const value = await variable.get();
10// value = "#146EF5"
11
12// Get Value of first Variable with custom value
13const variable = variables[1];
14const value = await variable.get({ customValues: true });
15// value = { type: 'custom', value: 'color-mix(in srgb, var(--blue-500), white 50%)' }

Designer ability

Checks for Authorization only

Designer abilityLocaleBranchWorkflowSitemode
canReadVariablesAnyAnyAnyAny