element.getAsset()

Retrieve an asset from an Image element.

Syntax

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

Returns

Promise<Asset> | null

A Promise that resolves to an Asset. If an element doesn’t have an asset, the method will return 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 // Check element type
10 if (imgEl.type === 'Image') {
11 // Get asset from Image element
12 const myAsset = await imgEl.getAsset()
13 console.log(myAsset)
14 }
15}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessAssetsanyanyanyany
Built with