element.setAsset(asset)

Add an asset to an Image element.

Syntax

1element.setAsset(asset: Asset | null): Promise<null>

Parameters

  • Asset: Asset - The asset to be inserted into the Image Element. Can be retrieved with the method webflow.getAssetById

Returns

Promise<null>

A Promise that resolves to null

Example

1// Get Selected Element
2const el = await webflow.getSelectedElement()
3
4// Check if element can have children
5if (el?.children) {
6 // Create a new Image Element using Element Presets
7 const imgEl = await el.append(webflow.elementPresets.Image)
8
9 // Get asset by ID
10 const asset = await webflow.getAssetById(assetId)
11
12 // Check element type
13 if (imgEl.type === 'Image') {
14 // Set asset as the "src" of the Image Element
15 await imgEl.setAsset(asset)
16 }
17}

Designer Ability

Designer AbilityLocaleBranchWorkflowSitemode
canModifyImageElementanymaincanvasany
Built with