Set variable value

variable.set(value, options?)

Set the value of the selected variable.

General Syntax

1variable.set(value: VariableValue | Variable | CustomValue, options?: {mode: VariableMode});

Parameters

  • value: VariableValue | Variable | CustomValue - The value to set for the variable. The value must match the variable’s type (e.g., a color variable requires a color value, a size variable requires a size value). You can also pass a Variable object to create a referenced variable or a CustomValue to set a custom value for the variable.

    Accepted Formats for ValueExamples
    Color namevariable.set("red");
    RGB Hexvariable.set("#ffcc11");
    RGBA Hexvariable.set("#fffcc11");
  • options: {mode: VariableMode} - An optional parameter to set the mode value of the variable.

Returns

Promise<null>

A Promise that resolves to null

Example

1// Get Collection
2const collection = await webflow.getDefaultVariableCollection()
3
4// Get Variable
5const variable = await collection?.getVariableByName("MyColorVariable")
6
7// Check Variable type and set color
8if (variable?.type === "Color") await variable.set("#fffcc11");

Try this example

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyVariablesAnyMainCanvasDesign