Freemarker Snippets
This page provides Freemarker code examples for common tasks in Bloomreach Content web applications.
List All Properties of a Bean
To display all properties of the document bean and their values, use the following snippet:
<ul> <#list document.properties?keys as prop> <li>${prop} = ${document.getProperty(prop)}</li> </#list> </ul>
Render an Image
To generate a link to the "original" variant of an image using HST, include the HST tag library and use the following code:
<#-- Assign the HST tag library --> <#assign hst=JspTaglibs["http://www.hippoecm.org/jsp/hst/core"] > <#-- Create a URL for the document.image.original bean --> <@hst.link var="img" hippobean=document.image.original /> <#-- Render the image element --> <img src="${img}"/>
Note: The HST tag library must be available in your Freemarker environment.
Render an HTML Field
To output an HTML field (such as the body field) and rewrite all internal links and embedded images to valid URLs, use the contentRewriter:
<@hst.html contentRewriter=contentRewriter hippohtml=document.body/>
Include Other Freemarker Templates
To include a template from the classpath:
<#include "/WEB-INF/lib/htmlTags.ftl">
To include a template from the repository (when your current template is also loaded from the repository):
<#-- Include a sibling template --> <#include "myinclude.ftl"> <#-- Include a template using a path relative to the current template location --> <#include "../../common/hst:templates/myinclude.ftl">
Set the Appropriate Locale
To set the Freemarker locale based on the HST mount configuration, use the following directive:
<#setting locale=hstRequest.requestContext.resolvedMount.mount.locale>