Determining if list is empty using render tags

116 views
Skip to first unread message

bobbykjack

unread,
Feb 8, 2010, 8:19:53 AM2/8/10
to RedDot CMS Users
Hi there,

I have a tempate, containing a list, which is reused by a few pages.
Within that template, I wish to hide certain contents if there are no
items in the list. Since I can't just wrap the contents in a standard
RedDot conditional block, I need to use render tags.

I'm using the method discussed previously on this group: looping
through the list and examining the result of the counter:

<reddot:cms>
<foreach itemname="item"
object="Context:CurrentPage.Elements.GetElement(lst_events).Value"
countername="counter">
<htmltext>Store:item[Int32:counter]</htmltext>
</foreach>
</reddot:cms>

There are <%!! Store:counter !!%> (+ 1) items.

However, if there are no items in the list at all, and the foreach
effectively doesn't execute, the counter appears to take its value
from the previous execution! I.e. if I switch between pages, my page
with an empty list uses the value of the previous non-empty list.

Is there a way around this? Make 'Store' local to each page view, for
example?

Regards,

- Bobby

Mark Radford

unread,
Feb 8, 2010, 9:51:02 AM2/8/10
to RedDot CMS Users
I'd try the following:

<%!! Context:CurrentPage.Elements.GetElement(lst_events).Value.Count !!
%>

I've used that for a container and it returns the number of items in
the container.

Hopefully that's helpful?

Mark

bobbykjack

unread,
Feb 11, 2010, 11:12:48 AM2/11/10
to RedDot CMS Users
Brilliant. I could have sworn I tried that, but I guess I probably
left the ".Value" out - grrr....

Thanks,

- Bobby

Mark Radford

unread,
Feb 12, 2010, 10:11:28 AM2/12/10
to RedDot CMS Users
No problem. Glad it worked :)

Mark

RedDotExpert

unread,
Feb 16, 2010, 10:21:47 PM2/16/10
to RedDot CMS Users
I would recommend no using rendertag to loop a list due to the famous
rendertag cache issue.

I would recommend a combination of using list blockmarks to loop the
list, pull placeholder through and use rendertag if else conditionals.

Niket Goel

unread,
Feb 16, 2010, 10:58:14 PM2/16/10
to reddot-c...@googlegroups.com
You can also use the <conditonal> blockmarks for same.


--
You received this message because you are subscribed to the Google Groups "RedDot CMS Users" group.
To post to this group, send email to reddot-c...@googlegroups.com.
To unsubscribe from this group, send email to reddot-cms-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/reddot-cms-users?hl=en.


Reply all
Reply to author
Forward
0 new messages