Set variable modes on a style

style.setVariableModes(props, options?)

Apply multiple variable modes to a style. Each variable mode is associated with a variable collection. To apply multiple variable modes, you must provide a map of variable collection IDs to their corresponding variable mode IDs.


Syntax

1setVariableModes(
2 props: VariableModeStylePropertyMap,
3 options?: BreakpointAndPseudo
4): Promise<null>;

Parameters

  • props: VariableModeStylePropertyMap - A map of variable collection IDs to their corresponding variable mode IDs.
    VariableModeStylePropertyMap
    1// Example
    2const props: VariableModeStylePropertyMap = {
    3"collection-09e4110d-f4b6-45f9-3c1b-614c748a01c6": "mode-2a4f8a4e-eb9b-be56-f773-9e88c3669955",
    4"collection-b799d4ac-670a-8296-0f2c-e153c4b1b46b": "base",
    5"collection-cd77d4e3-58e8-aac2-e2e4-4f567d399c4b": "mode-f780f7e7-1b41-b353-f931-13de2c4a1234",
    6"collection-e4fba320-a8ce-aad6-a302-8f95cdac2c6a": "mode-a4a9e6df-f2a6-f5e8-97e9-59f264e37b90"
    7}
  • options?: BreakpointAndPseudo - The breakpoint and pseudo state for the style.

Returns

Promise<null>

A Promise that resolves to null.

Example

1// This example gets variable modes from the style of the currently selected element, then sets them a chosen style
2
3// Get Selected Element
4const selectedElement = await webflow.getSelectedElement()
5
6if (selectedElement?.styles) {
7 // Get Styles
8 const styles = await selectedElement.getStyles()
9 const primaryStyle = styles?.[0] // Get the primary style
10 const variableModes = await primaryStyle?.getVariableModes()
11
12 // Set Variable Modes on Selected Style
13 if (variableModes) {
14 await selectedStyle?.setVariableModes(variableModes)
15 }
16}

Try this example

Designer ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyStyleBlocksAnyAnyCanvasDesign