[Hippo-cms7-user] Content Blocks plugin

Jeroen Hoffman j.hoffman at onehippo.com
Wed Sep 26 09:38:03 CEST 2012


A tip: instead of separate getType() implementations with different strings 
(return "text", return "news" etc.) you could have a single implemention reading 
the annotation:

public String getType() {
   final Node nodeAnnotation = getClass().getAnnotation(Node.class);
   return (nodeAnnotation == null) ? null : nodeAnnotation.jcrType();
}


In the given example, you then check against the DocumentTypes.TEXT_BLOCK 
constant in jsp.


Jeroen


On 25-09-12 17:03, David Martin wrote:
> Thanks,
>
> I think I can start with this indeed.
>
> Regards,
>
> David
>
> On Tue, Sep 25, 2012 at 3:20 PM, Wouter Danes <Wouter.Danes at hinttech.com
> <mailto:Wouter.Danes at hinttech.com>> wrote:
>
>     CND:____
>
>     [website:contentblock] > hippo:compound, hippostd:relaxed____
>
>        orderable____
>
>     __ __
>
>     [website:textblock] > website:contentblock____
>
>        - website:title (string)____
>
>        + website:text (hippostd:html)____
>
>     __ __
>
>     [website:cpitems] > nt:base____
>
>        orderable____
>
>        + website:textitem (website:textblock)____
>
>     __ __
>
>     __ __
>
>     Interface for beans:____
>
>     package nl.myler.beans.contentblocks;____
>
>     __ __
>
>     import org.hippoecm.hst.content.beans.standard.HippoBean;____
>
>     __ __
>
>     /**____
>
>     * @author Wouter Danes____
>
>     */____
>
>     public interface ContentBlock extends HippoBean {____
>
>     __ __
>
>          String getType();____
>
>     __ __
>
>     }____
>
>     __ __
>
>     The textblock bean:____
>
>     package nl.myler.beans.contentblocks;____
>
>     __ __
>
>     import nl.myler.cms.DocumentTypes;____
>
>     import org.hippoecm.hst.content.beans.Node;____
>
>     import org.hippoecm.hst.content.beans.standard.HippoDocument;____
>
>     import org.hippoecm.hst.content.beans.standard.HippoHtml;____
>
>     __ __
>
>     /**____
>
>     * @author Wouter Danes____
>
>     */____
>
>     @Node(jcrType = DocumentTypes.TEXT_BLOCK)____
>
>     public class TextBlock extends HippoDocument implements ContentBlock {____
>
>     __ __
>
>          @Override____
>
>          public String getType() {____
>
>              return "text";____
>
>          }____
>
>     __ __
>
>          public String getTitle() {____
>
>              return getProperty(DocumentTypes.TextBlock.TITLE, "");____
>
>          }____
>
>     __ __
>
>          public HippoHtml getText() {____
>
>              return getHippoHtml(DocumentTypes.TextBlock.TEXT);____
>
>          }____
>
>     }____
>
>     __ __
>
>     Bean using the blocks:____
>
>     package nl.myler.beans;____
>
>     __ __
>
>     import nl.myler.beans.contentblocks.ContentBlock;____
>
>     import nl.myler.cms.DocumentTypes;____
>
>     import org.hippoecm.hst.content.beans.Node;____
>
>     __ __
>
>     import java.util.List;____
>
>     __ __
>
>     /**____
>
>     * @author Wouter Danes____
>
>     */____
>
>     @Node(jcrType = DocumentTypes.WEB_PAGE)____
>
>     public class WebPage extends BaseDocument {____
>
>     __ __
>
>          public String getTitle() {____
>
>              return getProperty(DocumentTypes.WebPage.TITLE, "");____
>
>          }____
>
>     __ __
>
>          public String getSummary() {____
>
>              return getProperty(DocumentTypes.WebPage.SUMMARY, "");____
>
>          }____
>
>     __ __
>
>          public List<ContentBlock> getParagraphs() {____
>
>              return getChildBeansByName(DocumentTypes.WebPage.PARAGRAPH,
>     ContentBlock.class);____
>
>          }____
>
>     __ __
>
>     }____
>
>     __ __
>
>     JSP that renders a WebPage bean:____
>
>     __ __
>
>     <%-- at elvariable id="document" type="nl.myler.beans.WebPage"--%>____
>
>     <%@ include file="/WEB-INF/jspf/htmlTags.jspf" %>____
>
>     <hst:headContribution category="title">____
>
>     <title><c:out value="${document.title}"/></title>____
>
>     </hst:headContribution>____
>
>     <div id="main">____
>
>     <div class="content">____
>
>     <h1><c:out value="${document.title}"/></h1>____
>
>     <c:forEach items="${document.paragraphs}" var="contentBlock">____
>
>     <c:choose>____
>
>     <c:when test="${contentBlock.type eq 'text'}">____
>
>     <tag:textBlock textBlockBean="${contentBlock}"/>____
>
>     </c:when>____
>
>     <c:otherwise><!-- Content block not recognized, type =
>     "${contentBlock.type}" --></c:otherwise>____
>
>     </c:choose>____
>
>     </c:forEach>____
>
>     </div>____
>
>     </div>____
>
>     __ __
>
>     Tag used:____
>
>     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>____
>
>     <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>____
>
>     <%@ taglib prefix="hst" uri="http://www.hippoecm.org/jsp/hst/core" %>____
>
>     <%@ taglib prefix="tag" tagdir="/WEB-INF/tags" %>____
>
>     __ __
>
>     <%@attribute____
>
>              name="textBlockBean"____
>
>              type="nl.myler.beans.contentblocks.TextBlock"____
>
>              description="The TextBlock to render"____
>
>              required="true"____
>
>              rtexprvalue="true"____
>
>              %>____
>
>     __ __
>
>     <c:if test="${not empty textBlockBean.title}">____
>
>     <h2><c:out value="${textBlockBean.title}"/></h2>____
>
>     </c:if>____
>
>     <hst:html hippohtml="${textBlockBean.text}"/>____
>
>     __ __
>
>     __ __
>
>     Hope this helps to start you out.. of course you can make a contentblock
>     render tag that has the choose in it.. But this project just started.. JAnd
>     I like my generics when I actually need them.____
>
>     __ __
>
>     *From:*hippo-cms7-user-bounces at lists.onehippo.org
>     <mailto:hippo-cms7-user-bounces at lists.onehippo.org>
>     [mailto:hippo-cms7-user-bounces at lists.onehippo.org
>     <mailto:hippo-cms7-user-bounces at lists.onehippo.org>] *On Behalf Of *David Martin
>     *Sent:* dinsdag 25 september 2012 14:47
>     *To:* hippo-cms7-user at lists.onehippo.com
>     <mailto:hippo-cms7-user at lists.onehippo.com>
>     *Subject:* [Hippo-cms7-user] Content Blocks plugin____
>
>     __ __
>
>     Hi,____
>
>     __ __
>
>     I've found this issue related to Content Blocks :
>     https://issues.onehippo.com/browse/HIPPLUG-399____
>
>     As I have the exact same issue (and that's why I've found it when looking
>     for tips...), could someone explain how to handle a document using content
>     blocks on the HST side? Some kind of associated templates (to each compound
>     used) could be very useful in order to build the rendered page.____
>
>     __ __
>
>     Thanks,____
>
>     __ __
>
>     --
>     David____
>
>
>     _______________________________________________
>     Hippo-cms7-user mailing list and forums
>     http://www.onehippo.org/cms7/support/forums.html
>
>
>
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



More information about the Hippo-cms7-user mailing list