简体   繁体   English

如何获取DWT中TemplateRepeatIndex的最大索引计数

[英]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 我在tridion中有一个组件,其元数据设计有一个名为“list”的字段,该字段使用Categories和Keywords填充

I used a DWT code to populate items present in the list using the following code using My DWT TBB 我使用DWT代码使用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. 所以对于这个我需要获得“TemplateRepeatIndex”的最大数量是否有任何内置函数来检查相同。

using Tridion-sp1,2011. 使用Tridion-sp1,2011。

You can solve this with the built in function: CollectionLength. 您可以使用内置函数解决此问题:CollectionLength。

When you have a multi-valued text field "multiValuedField" you can find the item count using the following expression: 当您有一个多值文本字段“multiValuedField”时,您可以使用以下表达式找到项目计数:

@@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. Collection Length接收一个表达式,该表达式是项的完全限定名称和包项的值选择器。

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. 这是有效的,因为@@和$ {}之间的字符串被解析为JScript。

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. 您可以检查TemplateRepeatIndex是否为0.如果不是 ,请在值前面输出逗号。

I believe the only way to do this would be to create a TBB that adds the field count as an item in the package. 我相信这样做的唯一方法是创建一个TBB,将字段数添加为包中的项目。 You would then be able to do the following: 然后,您就可以执行以下操作:

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

<!-- TemplateBeginIf cond="primary_topic" --> 
@@RenderComponentField('primary_topic',TemplateRepeatIndex)@@<!-- TemplateBeginIf cond="TemplateRepeatIndex &lt; PrimaryTopicCount"--> ,<!-- TemplateEndIf -->
<!-- TemplateEndIf -->

<!-- TemplateEndRepeat -->

Walter solved and explained this topic a few years ago by introducing a custom function. 几年前,沃尔特通过引入自定义功能解决并解释了这一主题。

http://sdltridionworld.com/community/extension_overview/dreamweavercia.aspx http://sdltridionworld.com/community/extension_overview/dreamweavercia.aspx

Don't forget to recompile his code for the current version of Tridion. 不要忘记为当前版本的Tridion重新编译他的代码。

Update : you can find all built-in functions (and examples of their usage) that Tridion has for use in DWT on this page: http://code.google.com/p/tridion-practice/wiki/BuiltInFunctionsForUseInHtmlTemplates 更新 :您可以在此页面上找到Tridion在DWT中使用的所有内置函数(及其用法示例): http//code.google.com/p/tridion-practice/wiki/BuiltInFunctionsForUseInHtmlTemplates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM