damfn
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
.
Arguments
Argument | Description |
---|---|
|
required A key that uniquely identifies an asset. The key is composed of an asset provider ID and a provider-specific asset ID. |
Get folder
Gets a Folder
based on an itemKey
. Deleted or hidden folders are not
returned.
Arguments
Argument | Description |
---|---|
|
required A key that uniquely identifies an asset. The key is composed of an asset provider ID and a provider-specific asset ID. |
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
Argument | Description |
---|---|
|
required Composite key that identifies the asset’s provider ID and provider-specific ID. |
|
required Name of the rendition. |
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
-
AssetRendition
getRendition(``Asset
asset, String renditionName)
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
info.magnolia.dam.api.metadata.AssetMetadata. The
metadata submaps are collected under the key metadata
.
Method signature
*) getAssetMapForAssetId(String itemKey)
and getAssetMap(String itemKey)
are both identical except for handling of non-existent assets. While the getAssetMapForAssetId
is null-safe, the getAssetMap
is not.
You should always check for existence of assets or provide a fallback when using the getAssetMap method.
|
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 info.magnolia.dam.api.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
)
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
Argument | Description |
---|---|
|
required Composite key that identifies the asset’s provider ID and provider-specific ID. |
|
required Name of the rendition. |