Magnolia 5.3 reached end of life on June 30, 2017. This branch is no longer supported, see End-of-life policy.

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

This page is about Magnolia 5.2.x / DAM 1.x. The way assets are registered and used changed. If you work with Magnolia 5.3+ see  DAM and the STK.

The DAM API 1.x is fully integrated with Standard Templating Kit (STK).

DAM STK interaction

Using the stkTextImage component as an example, we demonstrate below how the STK interacts with the DAM API 1.x. Images in components are backed by Assets.

Here's what happens when the STK renders an image

  • The TextImageModel is called by the textImage.ftl script. The component queries the DAM API for an asset.
    • The query argument is the assetIdentifier that is stored in the image property of the component. The assetIdentifier for the default JcrAssetProvider is a composite id, for example jcr:178effda-d054-4a5a-a8f0-f0546754484e.
    • TextImageModel has access to DamTemplatingFunctions by injection in the model class. The provided methods are bound to a DamManager implemented class that acts as a dispatcher for assets.
  • DamTemplatingFunctions retrieves the original Asset.
    • DamManager defines the appropriate AssetProvider to use. The provider is referenced in the first part of the composite id.
    • AssetProvider assembles the Asset based on the specified storage location. Direct access to the binary media data is provided. This is typically from the internal asset node but could potentially come from an external source.
    • Asset is returned to DamTemplatingFunctions.
  • Based on the MediaType, the Dam module defines the AssetRenderer to use. STK uses its own renderer STKAssetRenderer that uses the Imaging module to create Renditions.
    • STKAssetRenderer creates a Rendition.
    • Renditions requires context information, for example the current site and theme.
    • STKAssetRenderer overrides the getRendition(... method in order to create a specific Rendition containing the correct Rendition image link.
  • During the rendering phase asset Rendition is used to generate a URL to the generated image.

STKRenderer configuration

The STK defines its own renderer  STKRenderer . Here's the registration of  DamTemplatingFunctions in /modules/standard-templating-kit/renderers/contextAttributes/damfn. Methods provided by this class are exposed in templates as damfn.

Node nameValue





















Using assets in model classes

An  Asset is a simple POJO with getters and setters. To get an Asset from any model class or other business logic class add the following code to the class.

    // Get the DamTemplatingFunctions
    private DamTemplatingFunctions damTemplatingFunction;
    // Or based on your need
	// Get the DamManager
    private DamManager damManager;
    // BY Injection
    public CustomFunction(DamManager damManager, DamTemplatingFunctions damTemplatingFunction) {
        this.damManager = damManager;
		this.damTemplatingFunction = damTemplatingFunction;
    // OR by using Components
    public void myCustomMethod() {
        this.damManager = Components.getComponent(DamManager.class);
		this.damTemplatingFunction = Components.getComponent(DamTemplatingFunctions.class);

    public Asset getAsset() {
		String assetIdentifier = PropertyUtil.getString(content, getImageName());
 		return damManager.getAssetForId(assetIdentifier);

    public AssetMap getAssetMap() {
		String assetIdentifier = PropertyUtil.getString(content, getImageName());
 		return damTemplatingFunction.getAssetMapForAssetId(assetIdentifier);

Using assets in Freemarker scripts

Here are some examples you can use in your scripts. See Main methods for more examples.

[#assign assetMap = damfn.getAssetMapForAssetId(]    
[#assign asset = damfn.getAssetForId(]
[#assign assetMap2 = model.getAsset()]
[#assign asset2 = model.getAssetMap()]


For Magnolia 5 all getAsset... templating methods provided by  STKTemplatingFunctions are deprecated. Use the new get... methods provided by  DamTemplatingFunctions instead.