variable.set(value)
variable.set(value)
Set the value of the selected variable.
Parameters
Type | Accepted Formats for Value | Examples |
---|---|---|
Color | Strings of one of three formats: - Color name - Color rgb hex value - Color rgba hex value |
Color Name variable.set("primary", "red"); RGB Hex variable.set("primary", "#ffcc11"); RGBA Hex variable.set("primary", "#fffcc11"); |
Size | Object in the following format: { unit: “px” | “rem” | “em” | “vw” | “vh” | “svh” | “svw” | “ch” value: number } |
variable.set(“defaultLength”, { unit: “px”, value: 50 }); |
FontFamily | String of the font name (e.g., "Verdana") | variable.set(“defaultFont”, “Verdana”); |
Returns
Promise<null
>
A Promise that resolves to null
Example
// Get Collection
const collection = await webflow.getDefaultVariableCollection()
// Get Variable
const variable = await collection?.getVariableByName("MyColorVariable")
// Check Variable type and set color
if (variable?.type === "Color") await variable.set("#fffcc11");
Designer Ability
Designer Ability | Locale | Branch | Workflow | Sitemode |
---|---|---|---|---|
canModifyVariables | Any | Main | Canvas | Design |