I have a page with a list element attached. How do I determine the number of items in that list? Can use render tags, asp, or any other technique (so long as it works!)
4 Answers
Reading the render tags documentation I believe it may be possible to do this in a nicer way
So getting the list Element using this
Context:CurrentPage.Elements.GetElement(lst_myPages).Value
The Value property should return a page collection for list items so you should be able to do
Context:CurrentPage.Elements.GetElement(lst_myPages).Value.Count

- 2,238
- 19
- 27
-
1An old thread...but the modern, more efficient way to do this is `Context:Pages.GetPage(Guid:<%inf_GUID%>).GetElementByName(lst_myPages).Value.Count` (where inf_GUID is the page GUID) – neil Dec 11 '14 at 14:01
<!IoRangePreExecute>
<% lst_myPagesSize = 0 %>
<!IoRangeList>
<% lst_myPagesSize = lst_myPagesSize + 1%>
<!IoRangeRedDotMode><!--[if !IE]><%lst_myPages%><![endif]--><!/IoRangeRedDotMode>
<!/IoRangeList>
<!/IoRangePreExecute>
I think this is the fastest way. First counter = 0. Then in the list range increment the counter (keep in mind to include the list place-holder too in that block). After that you have the value in the counter.

- 11
- 1
Apparently, the only way to do this is to loop through the list, counting each item, e.g.
<reddot:cms>
<foreach itemname="testList"
object="Context:CurrentPage.Elements.GetElement(lst_myPages).Value"
countername="listCounter">
</foreach>
</reddot:cms>
The length is then available as:
<%!! Store:listCounter !!%>

- 15,689
- 15
- 65
- 97
-
Would be great if someone could confirm this (or, even better, come up with a proper way of finding the length!) – Bobby Jack Jul 03 '09 at 10:40
-
<%!! Store:listCounter !!%> gives the position on the loop (0,1,2..) – Riccardo De Contardi Nov 30 '20 at 16:29
In OpenText use this render tag to get the length of a list (name of list element: lst_Navigation):
<%!! Context:CurrentPage.GetElementByName(lst_Navigation).GetLinkedContents().Count !!%>
Context/RDObj: by ObjectLoader Context (alias: RDObj) you get access to objects of Management Server
CurrentPage: returns Page objekt from current page
GetElementByName: method from page object to get a page element by name
GetLinkedContents: returns a LinkList object
Count: returns the number of LinkList elements

- 701
- 5
- 16
-
1Please add some explanation to your answer such that others can learn from it. – Nico Haase Aug 13 '20 at 12:47
-
This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). You can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/low-quality-posts/26925589) – Suraj Bahadur Aug 13 '20 at 18:20
-
@SurajBahadur Its actually the best answer. Since Object Linklist does not have a property called Value at least in OpenText version >= 11. – aLx13 Aug 27 '20 at 13:14