A More Complete Example

Here is a more complete iterate tag, which renders all types of menu items:

<MENU:iterate id="currentObject"  menu="&lt;%=menu%&gt;" currentSectionID="<%= sec.getId() %>">
  <MENU:sectionView>
    <a class="section" href='<BEAN:write name="url"/>'>
      <BEAN:write name="text"/>
    </a>
  </MENU:sectionView>
  <MENU:articleView>
    <a class="article" href='<BEAN:write name="url"/>'>
      <BEAN:write name="text"/>
    </a>
  </MENU:articleView>
  <MENU:urlView>
    <a href='<BEAN:write name="url"/>'>
      <BEAN:write name="text"/>
    </a>
  </MENU:urlView>
  <MENU:spaceView>
    <BEAN:write name="text"/>
  </MENU:spaceView>
</MENU:iterate>

This example is still, however, very simple. It renders links and sets the HTML class attributes to appropriate values for each menu item type, but does not do much more. The sectionView, articleView, urlView and spaceView tags all have a number of attributes that can be used in various ways.

You can also directly access the object referenced by the menu item, by using the currentObject variable exposed by the iterate tag. For a section, the currentObject is a SectionItem, which has direct access to the section:

<MENU:sectionView>
  <a href='<BEAN:write name="url"/>'
     class="<BEAN:write name="currentObject"
                  property="section.parameter(menuclass)"/>">
    <BEAN:write name="text"/>
  </a>
</MENU:sectionView>

The property called section.parameter(menuclass) retrieves the section parameter called 'menuclass' from each section in the menu. This way, the top level section could define a default value, and entire section trees could be configured to a different value.

Here is another example that uses the information in a content item field to enrich the menu.

<%@ taglib uri="http://www.escenic.com/taglib/escenic-article" prefix="article"%>
<MENU:articleView>
  <BEAN:define id="articleItem" name="currentObject"
               type="com.escenic.menu.ArticleItem" />

  <a class="article" href='<BEAN:write name="url"/>'>
    <BEAN:write name="text"/>
  </a>

  <ARTICLE:use articleId="<%=articleItem.getArticleId()%>">
    <ARTICLE:field field="menutext"/>
  </ARTICLE:use>

</MENU:articleView>

In this example, the content item's menutext field is retrieved. However, the same method could be used to retrieve related images or an icon. The menu could even be expanded to include related content items.