Magnolia 5.3 reached end of life on June 30, 2017. This branch is no longer supported, see End-of-life policy.
This page is about Magnolia 5.2.x+ / DAM 2.0+ The way assets are registered and used changed. If you work with Magnolia 5.2+ or earlier, see DAM templating 1.x.
In Magnolia 5.3 / DAM 2.0 DamTemplatingFunctions
was moved to it's own DAM submodule. The new fully-qualified class name is info.magnolia.dam.templating.functions.DamTemplatingFunctions
. All of the exposed utility methods are still supported, but most are deprecated.
The DAM Templating module provides one main utility class,
DamTemplatingFunctions
, for use in templates and model classes. This class provides direct access to Assets
, Folders
, Maps
and AssetRenditions
and defines useful methods. Templating functions are exposed in Freemarker templates as damfn
.
can be injected into any model class.DamTemplatingFunction
@Inject public CustomFunction(DamTemplatingFunctions damTemplatingFunction) { this.damTemplatingFunction = damTemplatingFunction; } public Asset getAsset(String itemKey) { return this.damTemplatingFunctions.getAsset(itemKey); }
DamTemplatingFunctions
are exposed in Freemarker templates using damfn
in the same way as cmsfn
and stkfn
are used. For example:[#assign asset = damfn.getAssetForId(content.identifier)] [#assign assetMap = damfn.getAssetMap(asset)]
provides access to getAssetMap(Asset asset):Map<String,String>
Asset
and metadata
properties using
. For example:DamTemplatingFunctions
[#assign assetMap = damfn.getAssetMap(asset)] <br>assetMap.title = ${assetMap.title} <br>assetMap.metadata.dc.title = ${assetMap.metadata.dc.title}
DamTemplatingFunctions
are available in the STK. The renderer configuration is in /modules/standard-templating-kit/renderer/contextAttributes/stk/damfn
. See DAM and the STK for more information.
If your module is not dependent on the STK, extend your renderer configuration to include DamTemplatingFunctions
.
Your module needs to depend on the
magnolia-dam-templating
module. See Module dependencies for more.
To configure a custom renderer, in /modules/<module name>/renderers/<renderer name>/contextAttributes
:
damfn
.componentClass
and set the value to info.magnolia.dam.templating.functions.DamTemplatingFunctions
.name
and set the value to damfn
.Node name | Value |
---|---|
my-module | |
renderers | |
customRenderer | |
contextAttributes | |
cms | |
cmsfn | |
damfn | |
componentClass | info.magnolia.dam.templating.functions.DamTemplatingFunctions |
name | damfn |
class | info.magnolia.module.myModule.renderers.CustomRenderer |
Method | Description | Return |
---|---|---|
getAsset(String itemKey) |
| Asset |
getAsset(String providerId, String assetPath) |
| Asset |
getAssetForAbsolutePath(String providerId, String absoluteAssetPath) |
| Asset |
getAssetLink(info.magnolia.dam.api.Asset asset, com.google.common.net.MediaType mediaType, String renditionName) |
| String |
getAssetLink(String assetKey) |
| String |
getAssetLink(String itemKey, String renditionName) |
| String |
getAssetMap(info.magnolia.dam.api.Asset asset) |
| Map |
getAssetMap(String itemKey) |
| Map |
getAssetMapForAssetId(String assetKey) |
| Map |
getFolder(String itemKey) |
| Folder |
getFolder(String providerId, String folderPath) |
| Folder |
getItems(String providerId, info.magnolia.dam.api.AssetQuery assetQuery) |
| Iterator |
getRendition(info.magnolia.dam.api.Asset asset, com.google.common.net.MediaType mediaType, String renditionName) |
| AssetRendition |
getRendition(info.magnolia.dam.api.Asset asset, String renditionName) |
| AssetRendition |
getRendition(String itemKey, com.google.common.net.MediaType mediaType, String renditionName) |
| AssetRendition |
getRendition(String itemKey, String renditionName) |
| AssetRendition |
provides(String providerId, com.google.common.net.MediaType mediaType) |
| Boolean |
1.x method | 2.x method | Return |
---|---|---|
getAssetForId(String assetIdentifier) | getAsset(String) | Asset |
getAssetForPath(String assetPath) | getAssetForAbsolutePath(String, String) | Asset |
getAssetLinkForId(String assetKey) | getAssetLink(String) | String |
getAssetLinkForId(String itemKey, String renditionName) | getAssetLink(String, String) | String |
getAssetRendition(info.magnolia.dam.api.Asset asset, String renditionName) | getRendition(Asset, MediaType, String) | Asset |
getAssetRenditionForAssetId(String itemKey, String renditionName) | getRendition(String, MediaType, String) | Asset |
getAssetsForFilter(info.magnolia.dam.api.AssetQuery assetQuery) | getItems(String, AssetQuery) | List |
getAssetsFromFolderId(String folderKey) | getFolder(String) and the Folder.getChildren() | List |
OldToNewAsset
implements the DAM 2.x Asset API by wrapping an instance of the 1.x Asset
. This class is included in the DAM compatibility module and contains a list of methods of the old API that can and cannot be implemented in DAM 2.x.
Method | Conversion | Return |
---|---|---|
ItemKey getItemKey() | new ItemKey(oldApiAsset.getAssetProviderIdentifier(), oldApiAsset.getIdentifier()) | ItemKey |
String getFileName() | oldApiAsset.getFileName() + '.' + oldApiAsset.getFileExtension() | FileName |
getLink() | oldApiAsset.getLink() | Link |
isFolder() | false | Boolean |
isAsset() | true | Boolean |
Plain delegate methods | ||
| oldApiAsset.getName() | String |
| oldApiAsset.getLanguage() | String |
getComment() | oldApiAsset.getComment() | String |
getTitle() | oldApiAsset.getTitle() | String |
getSubject() | oldApiAsset.getSubject() | String |
getDescription() | oldApiAsset.getDescription() | String |
getCaption() | oldApiAsset.getCaption() | String |
getCopyright() | oldApiAsset.getCopyright() | String |
getMimeType() | oldApiAsset.getMimeType() | String |
getFileSize() | oldApiAsset.getFileSize() | Long |
getContentStream() | return oldApiAsset.getContentStream() | InputStream |
getPath() | oldApiAsset.getPath() | String |
getLastModified() | oldApiAsset.getLastModified() | Calendar |
Method | Description | Return |
---|---|---|
getCreated() | Returns null | Calendar |
<M extends AssetMetadata> M getMetadata(Class<M> metaDataType) | Throws UnsupportedOperationException | AssetMetaData |
getParent() | Throws UnsupportedOperationException | Folder |
getAssetProvider() | Throws UnsupportedOperationException | AssetProvider |