Magnolia 6.0 reached end of life on June 26, 2019. This branch is no longer supported, see End-of-life policy.
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.
Retrieves an Asset
by itemKey
.
Asset
getAsset(String itemKey)
itemKey | required A key that uniquely identifies an asset. The key is composed of an asset provider ID and a provider-specific asset ID. |
Asset
An asset by the given itemKey.
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.
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)
Gets a Folder
based on an itemKey
. Deleted or hidden folders are not returned.
Folder getFolder(String itemKey)
itemKey | required A key that uniquely identifies an asset. The key is composed of an asset provider ID and a provider-specific asset ID. |
Folder
.
A folder by the given item key.
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}
Folder getFolder(String providerId, String folderPath)
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.
AssetRendition getRendition(String itemKey, String renditionName)
itemKey | required Composite key that identifies the asset's provider ID and provider-specific ID. |
renditionName | required Name of the rendition. |
AssetRendition
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.
AssetRendition getRendition(Asset asset, String renditionName)
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
.
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.
asset | required
|
itemKey | required The composed item key. |
Map<String, Object>
A map with the properties of an asset.
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}
Gets a link to an Asset
. Returns null if Asset
is not found or in case of an exception.
String getAssetLink(String itemKey)
itemKey | required Composite key that identifies the asset's provider ID and provider-specific ID. |
String
The link to an asset by a given asset key.
damfn.getAssetLink(itemKey)
<img src="${damfn.getAssetLink("jcr:324aa329-7acc-4a21-a05e-d5f9b69bf7e4")}"/>
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.
String getAssetLink(String itemKey, String renditionName)
itemKey | required Composite key that identifies the asset's provider ID and provider-specific ID. |
renditionName | required Name of the rendition. |
String
The link to an asset rendition by given item key and rendition name.
damfn.getAssetLink(itemKey, renditionName)
<img src="${damfn.getAssetLink("jcr:324aa329-7acc-4a21-a05e-d5f9b69bf7e4", "small-square")}"/>
String getAssetLink(Asset asset, String renditionName)