Render tag foreach, list order

308 views
Skip to first unread message

RedDot in Toronto

unread,
Feb 20, 2009, 4:52:52 PM2/20/09
to RedDot CMS Users, bria...@gmail.com
I'm trying to pull some data from a list on another page, my render
tags work but the data that's returned doesn't display in the correct
order that the list appears in, in Smart Tree has anyone experienced
this?

<reddot:cms>
<foreach itemname="item"
object="Context:CurrentPage.Elements.GetElement(anc_auditHome).Value
[Int:0].Elements.GetElement(lst_navigation).Value"
countername="counter">
<htmltext>
<a href="<%!! Store:item[Int32:counter].GetUrl() !!
%>"><%!! Store:item[Int32:counter].Elements.GetElement
(hdl_title).Value !!%></a>
</htmltext>
</foreach>
</reddot:cms>

Problem.... if the list in smart tree appears as

1
2

The render tag above returns

2
1

even if I change the order and change it back.

bucky

unread,
Feb 20, 2009, 5:19:40 PM2/20/09
to RedDot CMS Users
The List-Items are ordered by there Guid if you read them via foreach.
As far as I know there is no way to avoid this behaviour.

When I had once the same issue I solved this by passing the result of
the foreach loop to a custom function where they where orderd in a
alphabetic order.

RedDot in Toronto

unread,
Feb 22, 2009, 11:36:50 AM2/22/09
to RedDot CMS Users
Thanks, I guess I'll add that to the Red Dot list of gotchas... as
convenient as render tags and navigation manager are they just don't
feel complete.

Netpark

unread,
Feb 26, 2009, 11:10:31 AM2/26/09
to RedDot CMS Users
I've hit the same problem recently.

The way I solved it was to load the render tag results into a multi-
dimensional array and then use ASP to sort the array result by my
preferred sort order (ascending / descending).

First - run a <foreach> loop to get the number of elements and use
this to create your initial array.

<reddot:cms>
<foreach itemname="item"
object="Context:CurrentPage.Elements.GetElement(anc_auditHome).Value"
countername="itemCounter">
</foreach>
</reddot:cms>
<%
Dim MyArray(<%!! Store:itemCounter !!%>,2)
MyCounter = 0
%>

Next - run another <foreach> loop to load your array

<reddot:cms>
<foreach itemname="item"
object="Context:CurrentPage.Elements.GetElement(anc_auditHome).Value"
countername="itemCounter">
<htmltext>
<%
MyArray(MyCounter,0) = "<%!! Store:item[Int32:counter].GetUrl() !!
%>"
MyArray(MyCounter,1) = "<%!! Store:item
[Int32:counter].Elements.GetElement(hdl_title).Value !!%>"
MyCounter = MyCounter + 1
%>
</htmltext>
</foreach>
</reddot:cms>

Next - sort your array using your favourite sort function (we use a
modified version of the 4guysfromrolla.com version, available at:
http://www.4guysfromrolla.com/webtech/012799-3.shtml).

<%
Const Col = 1 'Set this to: 0=sort by URL, 2=sort by headline
Call QuickSort(MyArray,0,MyCounter-1,col,"ORDER_ASC") 'this would sort
array by headline in ascending order
%>

Lastly, render the result.

<%
for i = 0 to MyCounter-1
response.write "<a href=" & MyArray(i,0) & ">" & MyArray(i,1)
& "</a>"
next
%>

It's a bit of a hassle to setup, but once you have it working, it's a
useful approach.

Hope that's of use...
Reply all
Reply to author
Forward
0 new messages