The FreeMarker Rendering Engine is designed to create new renditions by applying a FreeMarker template to a piece of content in a content node. It was introduced in version 3.3 as one of the first rendering engines available to the core rendition service. This rendering engine has a name of 'freemarkerRenderingEngine' and is represented by the class org.alfresco.repo.rendition.executer.FreemarkerRenderingEngine
Like all rendering engines, the FreeMarker Rendering Engine generates one rendition node from a given source node. It applies a FreeMarker template transformation to the content of the source node and parameters can be supplied to configure the transformation. The first parameters to describe are those that can be used to specify the FreeMarker template itself. All of these three parameters are optional, but one of them must be set for the engine to work:
PARAM_TEMPLATE: (String) the actual FreeMarker template itself (not a reference)
PARAM_TEMPLATE_NODE: (NodeRef) a reference for the node whose cm:content property contains the FreeMarker template
PARAM_TEMPLATE_PATH: (String) the path to the node whose cm:content property contains the FreeMarker template. The display path is used for this parameter. That is to say '/Company Home/...' as opposed to '/app:company_home/...'.
These constants are all defined in the BaseTemplateRenderingEngine class from which both the XSLT Rendering Engine and the FreeMarker Rendering Engine are derived. As mentioned earlier, one of these parameters must be specified in all rendering definitions that make use of the FreeMarker Rendering Engine. The order in which they are evaluated is the order in which they appear in the list above.
Another parameter that is specific to templating rendering engines (such as the FreeMarker Rendering Engine) is PARAM_MODEL. This parameter is a Map object (implementing java.util.Map) that contains entries whose keys are String objects and whose values are Serializable objects. These entries are passed on to the template service as part of the model that is combined with the source node and template to produce the rendition.
Finally, the FreeMarker Rendering Engine takes one other optional parameter, PARAM_IMAGE_RESOLVER. This parameter specifies a org.alfresco.service.cmr.repository.TemplateImageResolver which is used to resolve any image paths specified in the template.
The model passed to the template
The model passed by the FreeMarker Rendering Engine to the template service contains the following entries (as well as any that are provided by PARAM_MODEL):
date : the current date/time as a java.util.Date object
companyhome : the company home node as a org.alfresco.service.cmr.repository.NodeRef.
person : the current user as a org.alfresco.service.cmr.repository.NodeRef.
userhome : the current user home node as a org.alfresco.service.cmr.repository.NodeRef.
template : the node containing the FreeMarker template (if it exists) as a org.alfresco.service.cmr.repository.NodeRef.
imageresolver : the image resolver specified by the parameter PARAM_IMAGE_RESOLVER.
node : the source node being rendered, wrapped as a org.alfresco.repo.template.TemplateNode.
Model entries that are provided by the rendition definition via the PARAM_MODEL parameter are provided to the template with no namespace qualification.
FreeMarker Template Processing
The FreeMarker Rendering Engine processes FreeMarker templates using the org.alfresco.repo.template.FreemarkerProcessor. For more information on how to create and use custom FreeMarker templates see the FreeMarker Manual