You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by David Künzler <dk...@pxe.ch> on 2007/07/03 15:40:15 UTC

How to render subcontent / OFBiz News Component?

Hi,
By writing this mail I was able to find a solution (see end of message).
Nonetheless I submit the mail to help anyone who has the same problem or
want to comment/propose a better solution.

I built a web site as a hierarchy of Content and ContentAssociations.
Here is a sample content structure (where dr: means DataResource of the
Content):

my web site publish point
-> [ContentAssocTo] page 1 (dr:screens.xml#page)
-> [ContentAssocTo] page 2 (dr: screens.xml#page)
-> [ContentAssocTo] page 3 (dr: screens.xml#page)
-> -> [ContentAssocTo] left column content (dr:leftcolumn.ftl)
-> -> [ContentAssocTo] right column content (dr: rightcolumn.ftl)
-> -> -> [ContentAssocTo] product featuring (dr: product_featuring.ftl)
-> -> -> [ContentAssocTo] news 1 (dr:news.ftl)
-> -> -> [ContentAssocTo] news 2 (dr:news.ftl)
-> -> -> [ContentAssocTo] news 3 (dr:news.ftl)

My problem was how to implement the rightcolumn.ftl (which is included in
the page 3).

1. The product featuring is easy (there is only one featuring subcontent):
<@renderSubContentAsText mapKey="featuredproduct" contentId=contentId />
and this seems to work too (but deprecated?):
<@renderSubContentCache mapKey="featuredproduct" contentId=contentId />
or like this: ${thisContent.subcontent.featuredproduct }

2. But for the news it's not so easy. They are associated with the same
mapKey and a sequence for the sort order:
rightcolumn -> [ConentAssocTo:mapKey=news;sequence=1] -> news 1
rightcolumn -> [ConentAssocTo:mapKey=news;sequence=2] -> news 2
rightcolumn -> [ConentAssocTo:mapKey=news;sequence=3] -> news 3

How can I render news 1 first, then news 2, then news 3, ...?
-> Is there a <@render... ftl function that can do that?
-> I could loop over thisContent.subcontent_all but then I can't filter by
mapKey="news" and I can't sort by ContentAssoc.sequence.
-> I also tried <@loopSubContentCache ... and <@limitedSubContent ... with
no success.

- The WORKING SOLUTION for now is this rightcolumn.ftl *):
...
<#-- // GET THE SORTED LIST OF NEWS // -->
<#assign newsList 
	= delegator.findByAnd("ContentAssoc", 
	Static["org.ofbiz.base.util.UtilMisc"].toMap("contentId", contentId,
"mapKey", "news"), 
	Static["org.ofbiz.base.util.UtilMisc"].toList("sequenceNum")) 
/>
<#-- // LOOP NEWS LIST AND RENDER NEWS // -->
<#list newsList as currentNews >
	<@renderSubContent subContentId=currentNews.contentIdTo />
	<br /><br />
</#list>
...

comments:
- I don't like to have this code in the .ftl so I'll create a FreeMarker
Macro or Include or a Service and/or create a Screen for this output and
call the data preparation code in an action.
- If I have more time I'll create a more or less generic News component that
you can use in your OFBiz based web site.
- If someone already has something similar please let me know.

*) 
- take care about contentId and context.contentId not necessarily being the
same.
- instead of findByAnd() you may use findByAndCache()

-David
________________________________________
From: Al Byers [mailto:byersa@automationgroups.com] 
Sent: Montag, 2. Juli 2007 17:14
To: user@ofbiz.apache.org; dk@pxe.ch
Subject: Re: content management (cms)

David,

I doubt that there is a more stable version. I coded much of the original
CMS from David Jone's design, but Andrew Zeneski has added a lot of
enhancements with which I am still becoming familiar.

I am using CMS for sites other than e-commerce and would be glad to answer
your questions, if I can, though I struggle with it a bit, myself. 

-Al
On 7/2/07, David Künzler <dk...@pxe.ch> wrote:
Hi,

I'm using the content/WebSites/CMS functionality to build a Web Site and I
have many questions I'll post in the dev Mailing List.

For this list my question is which OFBiz version I should use. At the moment

I use the trunk from SVN which seems to have some bugs.

Is there a more stable version? Is there a more functional version (could
also be that someone has it but didn't commit yet)?



Is anyone using the CMS to build Web Sites (not just for e-commerce)? 



Thanks, David