Get Asset

element.getAsset()

Retrieve an asset from an Image element.

Syntax

element.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

// Get Selected Element
const el = await webflow.getSelectedElement()
// Check if element can have children
if (el?.children) {
// Create a new Image Element using Element Presets
const imgEl = await el.append(webflow.elementPresets.Image)
// Check element type
if (imgEl.type === 'Image') {
// Get asset from Image element
const myAsset = await imgEl.getAsset()
console.log(myAsset)
}
}

Designer Ability

Checks for authorization only

Designer AbilityLocaleBranchWorkflowSitemode
canAccessAssetsanyanyanyany