Magnolia 5.7 reached extended end of life on May 31, 2022. Support for this branch is limited, see End-of-life policy. Please note that to cover the extra maintenance effort, this EEoL period is a paid extension in the life of the branch. Customers who opt for the extended maintenance will need a new license key to run future versions of Magnolia 5.7. If you have any questions or to subscribe to the extended maintenance, please get in touch with your local contact at Magnolia.
When using a templating function you pass some parameters and get something back. The types of these arguments and returned objects are the same in many methods, and it is helpful to know these types. Read the Javadoc of typical templating function return types even if you do not know Java. The Javadoc gives you an idea what else you could do with the returned objects.
Some functions require a Node, whereas others ask for
The type from the JCR API. Since JCR is a tree oriented data structure, this type is useful when you want to find other nodes above (parent, ancestors) or below (children) the current node.
This Magnolia type is a wrapper for the above mentioned JCR node. ContentMap provides easy access to the node properties and is useful when you want to render these properties.
ContentMap and Node rendering context objects
- The rendering context object
contentprovides the current content node of the context as
- The rendering context object
model.nodeprovides the current content node of the context as
javax.jcr.Node, see model. If you have no model but need this type, use
cmsfn provides methods to convert
Node and ContentMap collections
Both types java.util.List and java.util.Collection either with Node or with ContentMap items might be required as arguments.
cmsfn provides methods to convert Collection<Node> to List<ContentMap> and from Collection<ContentMap> to List<Node>.
Example: Get the children nodes of the node of the current nodes, convert the returned list of nodes into list of contentMap items and iterate over the list of contentMap items.
Map (of an asset),
itemKey of an asset
Some methods in
damfn require a String argument called
itemKey. An item key uniquely identifies an asset among different asset providers.
When JCR is used as asset provider, the item key is composed of
jcr:<node-UUID>, for instance
jcr:20d6e4e3-fe53-4b23-8d64-6e67a1c1667f. Typically you need to get the item key from a content node that is created when a component is saved in the JCR.
Example: A component node contains a reference to an image
quam Occidental in
<p>It va esser tam simplic quam Occidental</p>
In a Java context, if you have an asset and want to know its item key as a String, use:
In a FreeMarker context, if you have an asset and want to know its item key as a String, use:
An asset is a digital resource with associated metadata. This interface provides many methods that you may want to call directly within your script.
A Folder represents a structural item holding Assets. Depending on the provider, this can be directly mapped to the concept of folders/directories (JCR, FileSystems, and so on); for others this might map to the concept of albums, playlists, sets, and so on.
Map of an asset and its metadata
The DAM templating functions (damfn) provide a method which returns a
java.util.Map containing all the bean properties of the asset.
Additionally, the map may contain further nested maps with the properties of classes implementing
If the asset is provided by the
dam), the following submaps are provided on the asset map:
|Metadata class||Key||Composed key||Example|
The renditions are defined per Theme in the Site. For instance the node
/modules/site/config/themes/examples-theme/imaging/variations/small-square defines in the theme "examples-theme" a rendition named "small-square".
Read Template definition to get an idea what a template definition is. Some templating functions require a
At least the template definition of the current template is always available as context object - see rendering context object
Using public method of returned objects
If you know the type of the returned object of a templating function, you can apply the public methods to the object to retrieve the return value of these methods. This works in almost every case but not for maps such as
- Line 1: Assign an object of type javax.jcr.Node to the variable
- Line 2: Use the
getPath()method which is a public method defined in javax.jcr.Node. It returns a String.
The script will print for instance: The path of the underlying jcr node in this context is /home/products.