variable.set(value, options?)

Set the value of the selected variable.

General Syntax

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

Parameters

  • value: VariableValue | Variable - The value for the variable. The value of the variable must match the variable type. (i.e A color variable must be a color value, and a size variable must be a size value)

    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");

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyVariablesAnyMainCanvasDesign
Built with