Get variable value

variable.get(options?)

Retrieves the value of the variable.

Syntax

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

Parameters

  • options: object - An optional parameter to include get specific information.
    • mode: VariableMode - The value of the variable in the specified variable mode.
    • customValues: boolean - Indicate whether to return the custom value of the variable. Defaults to 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 a value based on the variable type. The return type varies depending on:

  • The variable type (Color, Size, Number, etc.)
  • Whether the variable is an alias (references another variable)
  • Whether custom values are requested (customValues: true)
  • The specified variable mode (mode parameter)

Returns a value in one of these formats:

  • String: e.g. "red", "#ffcc11", "#fffcc11"
  • Variable reference: ColorVariable
  • Custom value: CustomValue

Return Type: Promise<string | ColorVariable | 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%)' }

Try this example

Designer ability

Checks for Authorization only

Designer abilityLocaleBranchWorkflowSitemode
canReadVariablesAnyAnyAnyAny