How can I find the maxlength of the number of items?

TemplateBeginIf cond="TemplateRepeatIndex == 0"


You need to use the CollectionLength function:


Refer to this question: https://stackoverflow.com/questions/12052182/how-to-get-the-maximum-index-count-for-templaterepeatindex-in-dwt

  • I got the error Variable 'CollectionLength' has not been declared. How to declare it? – wiske Sep 8 '15 at 9:24
  • What version are you on? What is the exact code you are using? – Andrey Marchuk Sep 8 '15 at 9:25
  • Tridion 2009 SP1 – wiske Sep 8 '15 at 9:29
  • I'm afraid it was added in the later version. You will probably have to implement it yourself – Andrey Marchuk Sep 8 '15 at 11:03
  • Check this extension, might do the trick for you: sdltridionworld.com/community/extension_overview/… – Nuno Linhares Sep 8 '15 at 11:46

Why not write a C# TBB to check the number of Items, In case you cannot use any external tools.


Item compItem = package.GetByType(ContentType.Component);
XmlDocument Links = new XmlDocument();
XmlNodeList OuterImageCount = Links.GetElementsByTagName("OuterImage");
string Count = (OuterImageCount.Count).ToString();
package.PushItem("ItemsCount", package.CreateStringItem(ContentType.Text, Count));

And in DWT you can read the ItemsCount item pushed to Package as:

Reading the value inside condition as:

<!-- TemplateBeginIf cond="TemplateRepeatIndex == ItemsCount" -->

And in case you want to use the value any where else in DWT, use: @@ItemsCount@@

Where OuterImage is the repeating element as

<Image>xlink:title="primary-icon-7" xlink:href="tcm:218-12168"></Image>

<Image>xlink:title="primary-icon-8" xlink:href="tcm:218-12169"></Image>
<Image>xlink:title="primary-icon-9" xlink:href="tcm:218-12170"></Image>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.