Q:

How to iterate over ContentMap in jsp in magnolia

I am new to Magnolia CMS and now I have some problems with iterating over ContentMap on my jsp

I want my page to display respectively link and linkText. JSTL tags like forEach don't work in this case, e.g. I type 
<c:forEach items="${content.events}" var="item">
  <a href="${item.link}" target="_blank">${item.linkText}</a>
</c:forEach>

Thus my question is what is the correct way of iterating contentMap in Magnolia?

A:

ContentMap is node properties exposed as a Map. What you want to iterate over are subnodes, hence it can't work.
Looking at your structure, it looks like a link list area, if that is so <cms:area name="events" /> should be enough in the component that renders area and in the area itself something like:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="cms" uri="http://magnolia-cms.com/taglib/templating-components/cms"%>
<div id="${def.parameters.divId}">
  <c:forEach items="${components}" var="component">
    <cms:component content="${component}" />
  </c:forEach>
</div>

where components should be exposed implicitly in the area. Try to get magnolia-templating-samples module from git/nexus for more examples like that.
HTH,
Jan

