Starting with version 2.5 the LibreCCM platform support Freemarker as an alternative to XSL. Freemarker is a project of the Apache Foundation and a well known and mature template engine for Java. The support for Freemarker in version 2.5 is a backport from the upcoming version 7 of the LibreCCM platform.
Compared to XSL Freemarker is a lot easier to use, especially if you have worked with other template engines like Twig, Velocity etc before. In version 7 of the LibreCCM platform Freemarker will be become the primary template engine. XSL will still be supported, but we recommanded that you port your themes to Freemarker. Why Freemarker and not one of the other template engines? Freemarker is able to process XML in a similar way than XSL.
Freemarker also allows it to define user defined directivies and functions. To make it easier to create impressive themes we provide functions and macros for Freemarker we provide several functions and macros which hide the complexity of the XML data model created by CCM from the template author. It is recommanded not to access the XML data model directly. Instead the provided functions should be used. Otherwise your theme might brake when the XML structure changes.
Freemarker themes have a different structure than the usual "old style" themes of LibreCCM.
ToDo
Several variables and functions are predefined and available without importing another file.
contextPathThe context path in which CCM is running.
contextPrefixThe context prefix.
dispatcherPrefixPrefix for the CCM dispatcher (usually /ccm)
hostThe current host.
modelThe XML document created by LibreCCM.
negotiatedLanguageThe language negoiated between the user agent and LibreCCM.
requestSchemeThe protocol (http or https).
selectedLanguageThe language selected by the user.
themePrefixThe prefix of the theme. Only available if a development theme is viewed.
getLocalizedTextString getLocalizedText(String key)
Returns the localized text from the resource bundle of the theme.
getContentItemTemplateString getContentItemTemplate(String objectType, view="DETAIL", style="")
This is an internal function!
Returns the path for the template of a content item of a specific type.
_formatDateTimeAn internal functions date time formatting. This functions should not be used directly.
Import path: <#import /language.ftl as Lang>
getAvailableLanguagesSequence getAvailableLanguages()
Returns the available languages for the current document as sequence. These sequence can be used for creating links for selecting the language:
<ul class="language-selector">
<#list Lang.getAvailableLanguages()?sort as lang>
<li class="${(lang==negotiatedLanguage)?then('selected', '')}">${lang}</li>
</#list>
</ul>
This example uses the list directive from Freemarker to iterate over the available languages returned by getAvailableLanguages The Freemarker build-in ?then is used together with the negotiatedLanguage variable to check if the curent language is the selected language. If this is the case a CSS class is added to the HTML.
Import path: <#import /utils.ftl as Utils>
getPageApplication()
Return the application of the current page.
getPageTitle()
Returns the title of the current page
getSiteHostName()
Returns the name of the host serving the site.
getSiteName()
Returns the name of the site.
getBooleanAttrValue(fromNode: Node attrName: String)
A helper function which tries to convert the value of the attribute attrName of the node fromNode to a boolean. The following values are interpreted as true: true, yes. All other values are interpreted as false.
fromNode A XML node
attrName The name of attribute to interpret as boolean
A boolean for the value of the attribute. If the attribute is not present in the provided node the function returns false.
formatDateTime(style: String date: Node)
Formats the value of date/time value node according to the provided style. The is defined in the theme manifest in the date-time-formats section. It is possible to define different styles for different languages. The style definition in the theme manifest must be in the format expected by the Java DateTimeFormatter class.
style A date-time format defined in the theme manifest. The format must be formatted as expected by the DateTimeFormatter class.
date The node providing the data of the date to format.
A date formatted as defined in style.
In the theme manifest in the following format is defined:
"date-time-formats": [
...
{
"style": "news",
"lang": "de",
"format": "dd.MM.YYYY"
},
{
"style": "news",
"lang": "en",
"format": "MM/dd/YY"
},
...
]
The use this format:
Utils.formatDateTime('news', News.getDateTime(item))
News.getDateTime gets the date of a news item. If the date of the news is 2019-04-01 the return value of the function for german is
01.04.2019
and for english:
4/1/19
This module provides functions for dealing with file attachments. A possible usage these functions:
<#list FileAttachments.getFileAttachments(item)>
<div class="file-attachments">
<h2>
${getLocalizedText("layout.page.main.fileAttachments")}
</h2>
<ul class="file-attachments">
<#items as file>
<#if FileAttachments.getFileType(file) == "caption">
<li class="caption">
<strong>${FileAttachments.getFileName(file)}</strong>
<p>
${FileAttachments.getFileDescription(file)}
</p>
</li>
<#else>
<li class="file-attachment">
<a href="${FileAttachments.getFileUrl(file)}">
<span class="fa fa-download"></span>
${FileAttachments.getFileDescription(file)}
(${FileAttachments.getMimeTypeFileExtension(file)},
${FileAttachments.getFileSize(file, "KiB")} KB)
</a>
</li>
</#if>
</#items>
</ul>
</div>
</#list>
getFileAttachments(item: ContentItemNode): Sequence
Return the file attachments of a content items
item The content item from which the file attachments are retrieved.
A sequence of the file attachments of the provided content item.
getFileType(file)
Returns the type of the file attachments which is either caption or file.
file The file attachment
The type of the file attachment.
getMimeType(file)
Returns the mime type of the file.
file The file
The mime type of the file.
getMimeTypeFileExtension(file)
Returns the usual file extension for the mime type of the file.
file The file
The usual file extension for the mime type of the file.
getFileSize(file unit="byte")
Returns the size of the file in the provided unit.
fileThe file
unit Optional parameter for unit in which the size is returned. Default value is byte. Supported values are byte, kB KiB, MB and MiB. All other values are interpreted as byte.
The size of the file in the provided unit.
getFileId(file)
Returns the ID of the file.
file The file
The ID of the file.
getFileName(file)
Returns the name of file.
file The file
The name of the file.
getFileDescription(file)
Returns the name of file.
file The file
The description of the file.
getFileUrl(file)
Returns the name of file.
file The file
The URL of the file.
Provides functions for dealing with image attachments of a content item.
Import path: <#import "/ccm-cms-assets-imagestep.ftl" as Images>
Example usage:
<#import "/ccm-cms-assets-imagestep.ftl" as Images>
<#list Images.getImageAttachments(item)>
<div class="image-attachments">
<#items as image>
<figure>
<div>
<a data-fancybox="gallery">
<img src="${Images.getImageUrl(image)}"
width="100%"
height="auto" />
</a>
</div>
<figcaption>
${Images.getImageCaption(image)}
</figcaption>
</figure>
</#items>
</div>
</#list>
getImageAttachments(item)
Get the image attachments of a content item
item The content item.
A sequence of the image attachments of the provided content item.
getImageId(image)
Get the ID of the provided image.
image The image.
The id of the image.
getImageName(image)
Gets the name of the provided image.
image The image.
The name of the image.
getImageCaption(image)
Gets the caption of the provided image.
image The image.
The caption of the image.
getImageSortKey(image)
Gets the sort key of the provided image.
image The image.
The sort key of the provided image.
getImageWidth(image)
Gets the width of the provided image.
image The image.
The width of the provided image.
getImageHeight(image)
Gets the height of the provided image.
image The image.
The height of the provided image.
getImageUrl(image)
Gets the URL of the provided image.
image The image.
The URL of the provided image.