Page tree
Skip to end of metadata
Go to start of metadata

damfn templating functions provides access to digital assets such as images. Use these functions to get an asset from Magnolia's built-in DAM or other asset providers. DAM functions also create asset renditions and links to assets.

Get asset

Retrieves an Asset by itemKey.

Method signature

Asset getAsset(String itemKey)

Arguments

itemKey

required

A key that uniquely identifies an asset. The key is composed of an asset provider ID and a provider-specific asset ID.

Returns

Asset

An asset by the given itemKey.

Usage

damfn.getAsset(itemKey)

[#assign itemKey = cmsfn.asContentMap(componentNode).image]
[#assign myAsset = damfn.getAsset(itemKey)]

In this example componentNode is the node of a Text and Image component.

Related functions

  • Asset getAsset(String providerId, String assetPath). Returns an asset from a given asset provider. The asset provider does not have to be Magnolia JCR.
  • Asset getAssetForAbsolutePath(String providerId, String absoluteAssetPath)

Get folder

Gets a Folder based on an itemKey. Deleted or hidden folders are not returned.

Method signature

Folder getFolder(String itemKey)

Arguments

itemKey

required

A key that uniquely identifies an asset. The key is composed of an asset provider ID and a provider-specific asset ID.

Returns

Folder.

A folder by the given item key.

Usage

damfn.getFolder(itemKey)

[#assign contentPageNode = cmsfn.root(currentNode).getNode("home")]
[#assign componentNode = contentPageNode.getNode("main/0") ]
[#assign folderItemKey = cmsfn.asContentMap(componentNode).image]
[#assign myAsset = damfn.getFolder(folderItemKey)]
folder-name: ${myAsset.name}

Related functions

  • Folder getFolder(String providerId, String folderPath)

Get asset rendition

Gets the AssetRendition for a given itemKey and renditionName. If the Asset exists but the rendition is not defined, it returns "default" rendition which is the same as the original asset.

Method signature

AssetRendition getRendition(String itemKey, String renditionName)

Arguments

itemKey

required

Composite key that identifies the asset's provider ID and provider-specific ID.

renditionName

 required

Name of the rendition.

Returns

AssetRendition

Usage

damfn.getRendition(itemKey, renditionName)

[#assign itemKey = cmsfn.asContentMap(componentNode).image]
[#assign myRendition = damfn.getRendition(itemKey, "small-square")!]

The example above assumes that you have defined a rendition (image variation) named small-square in your Theme.

Related functions

Create asset property map

Creates a map for a given Asset or a given itemKey containing all the bean properties of the asset. Additionally the map may contain further nested maps with the properties of classes implementing  AssetMetadata . The metadata submaps are collected under the key metadata.

Method signature

Map<String, Object> getAssetMap(Asset asset)

Map<String, Object> getAssetMap(String itemKey)

Map<String, Object> getAssetMapForAssetId(String itemKey) *

*) getAssetMapForAssetId(String itemKey) and getAssetMap(String itemKey) are both identical.

Arguments

asset

required

Asset

itemKey

required

The composed item key.

Returns

Map<String, Object>

A map with the properties of an asset.

Usage

damfn.getAssetMap(asset) or damfn.getAssetMap(itemKey)

[#assign myAsset = damfn.getAsset("jcr", "photos/pool.jpg")!]
[#assign myAssetMap = damfn.getAssetMap(myAsset)]
[#-- assign myAssetMap = damfn.getAssetMap("jcr:20d6e4e3-fe53-4b23-8d64-6e67a1c1667f")--]
fileSize: ${myAssetMap.fileSize}
name: ${myAssetMap.name}
title: ${myAssetMap.title}
width: ${myAssetMap.metadata.mgnl.width}
format: ${myAssetMap.metadata.dc.format}
  • Line 3 shows an alternative for line 1-2.
  • The existance of the metadata submaps (see lines 7, 8) depends on the implementation of your  AssetProvider  (see Map of an asset and its metadata). When JcrAssetProvider (fetching assets for the workspace dam) metadata.mgnl and metadata.dc are available.

Get link for asset

Gets a link to an Asset . Returns null if Asset is not found or in case of an exception.

Method signature

String getAssetLink(String itemKey)

Arguments

itemKey

required

Composite key that identifies the asset's provider ID and provider-specific ID.

Returns

String

The link to an asset by a given asset key.

Usage

damfn.getAssetLink(itemKey)

 

 <img src="${damfn.getAssetLink("jcr:324aa329-7acc-4a21-a05e-d5f9b69bf7e4")}"/>

Get link for asset rendition

Gets the link to the AssetRendition for a given itemKey and renditionName . Returns null in the case of an exception or if Asset or AssetRendition are not found. If the Asset exists but the rendition is not defined, it returns the link to the "default" rendition which is the same as the original asset.

Method signature

String getAssetLink(String itemKey, String renditionName)

Arguments

itemKey

required

Composite key that identifies the asset's provider ID and provider-specific ID.

renditionName

required

Name of the rendition.

Returns

String

The link to an asset rendition by given item key and rendition name.

Usage

damfn.getAssetLink(itemKey, renditionName)

 <img src="${damfn.getAssetLink("jcr:324aa329-7acc-4a21-a05e-d5f9b69bf7e4", "small-square")}"/>

Related functions

  • String getAssetLink(Asset asset, String renditionName)