Content Item Templates

Here is the temp-dev publication's article/markup/news.jsp template:

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<h2>
  ${article.fields.title}
</h2>
<div class="date">
  <fmt:formatDate value="${article.lastModifiedDateAsDate}"/>
</div>
<div class="byline">
  Written by ${article.author.name}
</div>
<div class="summary">
  ${article.fields.summary}
</div>
<div class="body">
  ${article.fields.body}
  <c:forEach items="${article.relatedElements.images.items}" var="related">
    <img src="${related.content.fields.alternates.value.SmallSquare.href}" alt="${related.fields.caption}"
        width="${article.fields.alternates.value.SmallSquare.width}" height="${article.fields.alternates.value.SmallSquare.height}"/>
  </c:forEach>
</div>

<div class="stories">
  <h3>Related articles</h3>
  <ul>
    <c:forEach items="${article.relatedElements.stories.items}" var="related">
      <li>
        <a href="${related.content.url}">${related.fields.title}</a>
      </li>
    </c:forEach>
  </ul>
</div>

This file contains the HTML needed to present the content item, and uses JSP expressions to retrieve the desired fields from the article bean at the appropriate points in the document. Note in particular:

  • The article bean's author property is a PresentationPerson bean, which in turn has a name property that holds the author's name. This property can be directly accessed using the expression language, as shown in the "byline" div above.

  • The "body" div contains the body field, followed by a JSTL forEach element that displays all the content item's related images (images is the name of a relation-type defined in the content-type resource). The article bean's articles property is an array of PresentationRelationArticle elements.

  • Similarly, the "stories" div contains a JSTL forEach element that is used to output an HTML link to all the content item's related stories (stories is the name of a relation-type defined in the content-type resource).