This article covers a Bloomreach Experience Manager version 11. There's an updated version available that covers our most recent release.

04-07-2016

Freemarker Snippets

List all properties of a bean

To list all properties of the document bean with their values:

<ul>
  <#list document.properties?keys as prop>
    <li>${prop} = ${document.getProperty(prop)}</li>
  </#list>
</ul>

Render an image

This snippet will cause HST to create a link to the "original variant" of an image. Make sure you have HST's tag library included.

<!#-- Make sure you have the hst TabLib assigned -->
<#assign hst=JspTaglibs["http://www.hippoecm.org/jsp/hst/core"] >

<!#-- Create URL that points to the document.image.original bean -->
<@hst.link var="img" hippobean=document.image.original />

<!#-- Render the image -->
<img src="${img}"/>

Render an HTML field

The contentRewriter causes all internal links and images embedded in the HTML content (the body field in this example) to be converted to valid URLs:

<@hst.html contentRewriter=contentRewriter hippohtml=document.body/>

Including other Freemarker templates

Include a template from the classpath:

<#include "/WEB-INF/lib/htmlTags.ftl">

Include a template from the repository (in a template that is loaded from the repository):

<#-- Include a sibling -->
<#include "myinclude.ftl">

<#-- Include from a path relative to the current template location -->
<#include "../../common/hst:templates/myinclude.ftl">

Setting the appropriate Locale

Derive the Locale from the used HST mount as follows:

<#setting locale=hstRequest.requestContext.resolvedMount.mount.locale>
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?

    We rely on cookies

    to optimize our communication and to enhance your customer experience. By clicking on the Accept and Close button, you agree to the collection of cookies. You can also adjust your preferences by clicking on Manage Preferences. For more information please see our Privacy policy.

    Manage cookies
    Accept & close

    Cookies preferences

    Accept & close
    Back