Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Maximum index count for TemplateRepeatIndex in DWT

I have a component in tridion where its metadata design has a field called 'list' which is populated using Categories and Keywords

I used a DWT code to populate items present in the list using the following code using My DWT TBB

<!-- TemplateBeginRepeat name="Metadata.list" -->

    <!-- TemplateBeginIf cond="list" --> 
        @@RenderComponentField('list',TemplateRepeatIndex)@@ ,
    <!-- TemplateEndIf -->

<!-- TemplateEndRepeat -->

but Im getting preview as

one,two,three,four,five,

desired output should be like: one,two,three,four,five

so for this i need to get the maximum count of "TemplateRepeatIndex" Is there any inbuilt function to check the same.

using Tridion-sp1,2011.

like image 789
User 4.5.5 Avatar asked Aug 21 '12 09:08

User 4.5.5


2 Answers

You can solve this with the built in function: CollectionLength.

When you have a multi-valued text field "multiValuedField" you can find the item count using the following expression:

@@CollectionLength("Component.Fields.multiValuedField")@@

Collection Length receives an expression that is the fully qualified name of an item and a value selector of a package item.

The value returned is a string. When you need to perform an integer comparison or calculation you need to parse the value to an integer:

@@parseInt(${CollectionLength("multivalued")})@@

This works because the string between @@ and ${} is parsed as JScript.

like image 158
Arjen Stobbe Avatar answered Sep 26 '22 07:09

Arjen Stobbe


An easy solution would be to switch your logic around.

You can check if TemplateRepeatIndex is 0. If it is not, output the comma in front of the value.

like image 26
Peter Kjaer Avatar answered Sep 22 '22 07:09

Peter Kjaer