How can I find the maxlength of the number of items?
TemplateBeginIf cond="TemplateRepeatIndex == 0"
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It only takes a minute to sign up.
Sign up to join this communityHow can I find the maxlength of the number of items?
TemplateBeginIf cond="TemplateRepeatIndex == 0"
You need to use the CollectionLength
function:
@@CollectionLength("Component.Fields.multiValuedField")@@
Refer to this question: https://stackoverflow.com/questions/12052182/how-to-get-the-maximum-index-count-for-templaterepeatindex-in-dwt
Why not write a C# TBB to check the number of Items, In case you cannot use any external tools.
Example:
Item compItem = package.GetByType(ContentType.Component);
XmlDocument Links = new XmlDocument();
Links.LoadXml(compItem.Content.OuterXml);
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
<OuterImage>
<LinkUrl>http://www.google.co.in</LinkUrl>
<Image>xlink:title="primary-icon-7" xlink:href="tcm:218-12168"></Image>
</OuterImage>
<OuterImage>
<LinkUrl>http://www.google.co.in</LinkUrl>
<Image>xlink:title="primary-icon-8" xlink:href="tcm:218-12169"></Image>
</OuterImage>
....
....
<OuterImage>
<LinkUrl>http://www.google.co.in</LinkUrl>
<Image>xlink:title="primary-icon-9" xlink:href="tcm:218-12170"></Image>
</OuterImage>