Usage in an HST Site

In order to use a Resource Bundle Document in a JSP page, the JSP page needs to load it first. The standard way to load a Resource Bundle is through the <fmt:setBundle/> tag, which is part of the Java Standard Tag Library (JSTL). This tag, however, only allows to load Resource Bundles from the Classpath. To overcome this limit, the HST tag library provides a <hst:setBundle/> tag, which inherits all the standard behavior from <fmt:setBundle/>, and adds the ability to look up resource bundles inside the repository, using its unique ID as the key. This allows you to load document-based Resource Bundles, stored inside your CMS.

Once you have loaded a Resource Bundle, you can use it in your page using the <fmt:message/> tag. Specify the key to retrieve in the “key” attribute (for example, <fmt:message key="search.results"/>). Let's look at a sample JSP code:

<fmt:setLocale value="en_US"/>
<hst:setBundle basename="com.myhippoproject.example"/>
<form action="<hst:link siteMapItemRefId='search'/>" method="get">
  <div class="input-group">
    <fmt:message key='' var="placeholder"/>
    <input type="text" placeholder="${fn:escapeXml(placeholder)}" name="query">
    <div class="input-group-btn">
      <fmt:message key='' var="label"/>
      <button class="btn btn-default" type="submit">${fn:escapeXml(label)}</button>

The first line set the locale to English using the <fmt:setlocale/> tag. The second line uploads the Resource bundle we created in the tutorial by specifying its unique ID. The following lines produce an HTML fragment which makes use of some of the resources of the bundle. The result contains the resources for the American English locale. By replacing the first line with <fmt:setLocale value="de"/>, the HTML fragment will contain the resources for the German locale instead.

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?