[opencms-dev] How to know the contentload result size prior to looping?

Mathias Lin | SYSVISION mail at mathiaslin.com
Tue May 26 03:39:45 CEST 2009


One way would be using the contentload-tag to do the counting before hand:

<c:set var="cnt" value="0"/>
<cms:contentload collector="allInFolder" param="${philosophiesPath}|
philosophy"><c:set var="cnt" value="${cnt++}"/></cms:contentload>

Then you can do the check...
<c:if test="${cnt ge 1}"> ... </c:if>

But note: it occurs to me that there's a bug in the contentload/loop when
there are no elements in the folder and you activate direct edit. The
contentload loop always counts 1, regardless whether there is one or none
element found in a folder.
This problem has been reported before in the mailing list and we came across
it as well in a recent project, seems like a bug to me. Not sure if it's
been fixed in 7.5 already.



Sacha-11 wrote:
> 
> Hi,
> 
> I have a bit of a basic problem here. I can't seem to find a solution for
> when I try to find the number of results of a contentload without looping
> through the results.
> E.g.:
> 
> <div id="philosophies">
> <cms:contentload collector="allInFolder" param="${philosophiesPath}|
> philosophy">
>     <cms:contentinfo var="info" />
>     <%-- Some initialization based on the result size in the "info"
> variable. --%>
>     <%-- After the initialization all results must be looped. --%>
> </cms:contentload>
> </div>
> 
> If I do it this way, the initialization of the variables naturally occurs
> for every result.
> Another problem I am confronted with is that the div with id
> "philosophies"
> should be displayed only when there is at least one result for the
> contentload.
> If I can solve one problem the second one is solved in the same way
> ofcourse.
> 
> 


-----
Mathias Lin
SYSVISION Ltd., China
http://www.sysvision.com
-- 
View this message in context: http://www.nabble.com/How-to-know-the-contentload-result-size-prior-to-looping--tp23706686p23715681.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list