How to iterate through all child components in your renderer (jsp)

Sometimes, you just want to aggregate the output of all child HstComponents in your JSP/freemarker template, and you do not know on beforehand which child components to expect. Thus, for example, the normal way does not apply:

Explicit child components:

<body>
  <div id="custom-doc" class="yui-t6">
    <hst:include ref="header"/>
    <hst:include ref="body"/>
    <hst:include ref="footer"/>
  </div>
</body>

When you do not know that you have a child component header, body and footer, you can also use the following for aggregating all child components (in the order of the configuration they are rendered)

Aggregate all child components in a JSP:

<body>
  <div id="custom-doc" class="yui-t6">
    <hst:defineObjects/>
    <c:forEach var="childContentName" items="${hstResponse.childContentNames}">
       <hst:include ref="${childContentName}"/>
    </c:forEach>
  </div>
</body>

And its freemarker equivalent:

<body>
  <div id="custom-doc" class="yui-t6">
    <@hst.defineObjects/>
    <#list hstResponseChildContentNames as childContentName>
      <@hst.include ref="${childContentName}"/>
    </#list>
  </div>
</body>
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?