您好,我在循环链接组件时遇到问题。
我创建了一个带有产品项的 EmailSetup(View UML diagram ) 组件。
产品组件具有架构 (EmailBlockWithCode)。
产品:
- - 代码 = “wms_III”
- - 物品:
- - 密钥 = “产品密钥”
- - 内容 = “产品内容”
- - 呼吁采取行动 :
- - 物品:
- - 钥匙 = “蓝牙钥匙”
- - 内容 =“蓝牙内容”
- - 物品:
当我用代码循环这个组件时:
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<product name="@@Product.Code@@">
<!-- TemplateBeginRepeat name="Product.Fields.Item" -->
<@@Product.Fields.Item.Key@@><![CDATA[@@Product.Fields.Item.Content@@]]></@@Product.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
<!-- TemplateBeginRepeat name="Product.Fields.CallToAction" -->
@@GetComponent(Field,'CallToAction')@@
<@@CallToAction.Fields.Item.Key@@><![CDATA[@@CallToAction.Fields.Item.Content@@]]></@@CallToAction.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
</product>
<!-- TemplateEndRepeat -->
</products>
这是函数 GetComponent
[TemplateCallable]
public string GetComponent(string tcmUri, string packageVariable) {
Assert.NotEmpty("tcmUri", tcmUri);
Assert.NotEmpty("packageVariable", packageVariable);
IdentifiableObject identifiableObject = m_Engine.GetObject(new TcmUri(tcmUri));
if (identifiableObject as Component == null) {
throw new BuildingBlockException("Given tcmUri '" + tcmUri + "' is not a Component.");
}
Item previousItem = m_Package.GetByName(packageVariable);
if (previousItem != null) {
m_Package.Remove(previousItem);
}
Component component = identifiableObject as Component;
m_Package.PushItem(packageVariable, m_Package.CreateTridionItem(ContentType.Component, component));
return "";
}
我的输出是:
<products>
<product name="wms_III">
</product>
</products>
所以我的问题是代码没有循环
遍历“项目”(键 = ProductKey;内容 = ProductContent)我找到了一个函数 IteratingOverMultivalueEmbeddedFields 但这也不会循环我的产品。代码:
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@GetComponent(Field,'Product')@@
<!-- TemplateBeginRepeat name="Product.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
<!-- TemplateBeginIf cond="Field.ContentType = 'text/plain'" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndIf -->
<!-- TemplateBeginIf cond="Field.ContentType = 'tridion/field'" -->
<!-- TemplateBeginRepeat name="Field.Fields" -->
@@Field.Name@@
<!-- TemplateBeginRepeat name="Field.Values" -->
@@RenderComponentField(FieldPath, TemplateRepeatIndex)@@
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
<!-- TemplateEndRepeat -->