examples

{{{abbreviate message safeString=true maxLength=30}}}
/*
If message =
"The goal of AEM Communities is to quickly create a community engagement site."
Then abbreviate would return
"The goal of AEM Communities is"
*/

content-loadmore

A helper to add two spans under a div, one for the full text and the other for the less text, with the ability to toggle between the two views.

parameters

context : String
(optional) Default is the empty string.

numChars : number
(optional) The number of characters to display when not displaying full text. Default is 100.

moreText : String
(optional) The text to display indicating there is more text to display. Default is "more".

ellipsesText : String
(optional) The text to display indicating there is hidden text. Default is "...".

safeString : boolean
(optional) Boolean value indicating whether or not to apply Handlebars.SafeString() before returning the result. Default is false.

example

{{content-loadmore context numChars=32 moreText="go on" ellipsesText="..." }}
/*
If context =
"Here is the initial less content and this is more content."
Then content-loadmore would return
"Here is the initial less content<span class="moreelipses">...</span>&nbsp;<span class="scf-morecontent"><span>and this is more content.</span>&nbsp;&nbsp;<a href="" class="scf-morelink" evt="click=toggleContent">go on</a></span>"
*/

dateUtil

A helper to return a formatted date string.

parameters

context : number
(optional) a millisecond value offset from January 1, 1970 (epoch). Default is the current date.

format : String
(optional) The date format to apply. Default is "YYYY-MM-DDTHH:mm:ss.sssZ" and the result appears as "2015-03-18T18:17:13-07:00"

example

includeClientLib

A helper that includes an AEM html client library, which can be a js, a css or a theme library. For multiple inclusions of different types, for example js and css, this tag needs to be used multiple times in the Handlebars script.

This helper, appropriate only on the server-side, provides functionality similar to ui:includeClientLib for JSP scripts.

parameters

categories : String
(optional) A list of comma-separated client lib categories. This will include all Javascript and CSS libraries for the given categories. The theme name is extracted from the request.

theme : String
(optional) A list of comma-separated client lib categories. This will include all theme related libraries (both CSS and JS) for the given categories. The theme name is extracted from the request.

js : String
(optional) A list of comma-separated client lib categories. This will include all Javascript libraries for the given categories.

css : String
(optional) A list of comma-separated client lib categories. This will include all CSS libraries for the given categories.

It is possible to pass an object nested within the current context as the context, such as this.url or this.id (see following examples of simple and block helpers).

Block helpers are functions that can be called from anywhere in the template. They can invoke a block of the template zero or more times with a different context each time. They contain a context between {{#name}} and {{/name}}.

Handlebars provides a final parameter to helpers named 'options'. The special object 'options' includes

optional private data (options.data)

optional key-value properties from the call (options.hash)

ability to invoke itself (options.fn())

ability to invoke the inverse of itself (options.inverse())

It is recommended that the HTML String content returned from a helper is a SafeString.

Custom SCF Helpers

Custom helpers must be implemented on the server-side as well as the client-side, especially when passing data. For SCF, most templates are compiled and rendered on the server-side as the server generates the HTML for a given component when the page is requested.

Server-side Custom Helpers

To implement and register a custom SCF helper on the server-side, simply implement the Java interface TemplateHelper, make it an OSGi Service and install it as part of an OSGi bundle.