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.
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
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.
(See Asset to see all public methods indicating the available properties.)
Additionally, the map may contain further nested maps with the properties of classes implementing AssetMetadata. The metadata sub maps are collected under the key
If the asset is provided by the JcrAssetProvider (that means, if the asset derives form the JCR workspace
dam), the following submaps are provided on the asset map:
|Metadata class||Key||Composed key||Example|
An AssetRendition is a "variation" on a asset, for a specific MimeType.
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".
The Site object gives access to its appendant theme (if a theme is defined on the site) and some other objects as linked domains, mappings, and so on.
At least the template definition of the current template is always available as context object - see rendering context object
A JsonBuilder object is a builder for converting JCR nodes into json. The class offers many public methods to adapt the nodes structure and the properties. JsonBuilder is the return types of all methods of
jsonfn (JsonTemplatingFunctions) and of most of the methods of JsonBuilder. Method #print returns the json as string.
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 ContentMap.
- 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.