Taxonomy Plugin Delivery Tier Configuration - BloomReach Experience - Open Source CMS
07-01-2019

Taxonomy Plugin Delivery Tier Configuration

Configure and use the Taxonomy Plugin in the delivery tier (HST).

Configure TaxonomyManager and Beans Annotated Classes

After adding and configuring the Taxonomy plugin using the setup application, you will need to tell Spring to create a TaxonomyManager component. An example of a configuration can be found in the taxonomy-demo: taxonomy.xml

Copy this file into src/main/resources/META-INF/hst-assembly/overrides in your project's site/components module.

Make sure the hst-beans-annotated-classes context parameter is defined in src/main/webapp/WEB-INF/web.xml in your project's site module (if you created your project from the archetype, it should already be there):

  <context-param>
    <param-name>hst-beans-annotated-classes</param-name>
    <param-value>classpath*:org/example/**/*.class
      ,classpath*:org/onehippo/**/*.class
      ,classpath*:com/onehippo/**/*.class
      ,classpath*:org/onehippo/forge/**/*.class
    </param-value>
  </context-param>

Render a Document's Categories

Content Bean

After you add taxonomy to a document type using the Essentials setup application, make sure to run the Beanwriter tool to update the document type's content bean class. This will add a getKeys() method to the bean class:

    public String[] getKeys() {
        return getProperty("hippotaxonomy:keys");
    }

JSP Template

The Taxonomy Plugin includes a tag library (TLD) containing a single tag (TaxonomyTag) to help render a document's categories.

Declare the taxonomy tag library:

<%@ taglib uri="http://www.hippoecm.org/jsp/hst/taxonomy" prefix='tax'%>

Use the tax:categories tag to obtain a list of lists of org.onehippo.taxonomy.api.Category objects, then iterate through the nested lists and render each category for the document's locale:

<tax:categories var="list" keys="${document.keys}" />
<c:forEach var="ancestors" items="${list}">
  <ul>
    <c:forEach var="category" items="${ancestors}">
      <c:set var="categoryInfo" value="${category.infos[document.locale]}" />
      <li>${categoryInfo.name}</li>
    </c:forEach>
  </ul>
</c:forEach>

Freemarker Template

Currently, due to HIPPLUG-1408 and HIPPLUG-1409, Freemarker support is limited. Your best option is to obtain all required taxonomy information within an HST component (see below) and use request attributes to make that information available to the Freemarker template.

Obtain a Taxonomy within an HST Component

Import the required classes, obtain the TaxonomyManager, then obtain a taxonomy by the name of its root node (exampletaxonomy in this example):

import org.onehippo.taxonomy.api.Taxonomy;
import org.onehippo.taxonomy.api.TaxonomyManager;

TaxonomyManager taxonomyManager =
  HstServices.getComponentManager().getComponent(TaxonomyManager.class.getName());
Taxonomy taxonomy = taxonomyManager.getTaxonomies().getTaxonomy("exampletaxonomy");

The taxonomy demo shows several ways to use a Taxonomy object from within the delivery tier: to search for a taxonomy value, to generate the full taxonomy tree and to locate an entry.

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?