Hello,
I got a problem with looping over my linked component.
I created a EmailSetup(View UML diagram) Component with a product item.
The product Component has schema (EmailBlockWithCode).
Product:
When i loop over this component with the code :
<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>
This is the function 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 "";
}
My output is :
<products>
<product name="wms_III">
</product>
</products>
So my problem is that the code doesn't loop
over the 'item' (key = ProductKey; content = ProductContent)
I have found a function IteratingOverMultivalueEmbeddedFields but this also won't loop my product. code:
<!-- 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 -->
I fixed this by using this code. Not the best but it works.
<products>
<!-- TemplateBeginRepeat name="Component.Fields.Product" -->
@@RenderComponentPresentation(Field, "tcm:75-72162-32")@@
<!-- TemplateEndRepeat -->
</products>
and the renderComponentPresentation loads another dwt with this:
<product name="@@Component.Fields.Code@@">
<!-- TemplateBeginRepeat name="Component.Fields.Item" -->
<@@Field.Key@@><![CDATA[@@Field.Content@@]]></@@Field.Key@@>
<!-- TemplateEndRepeat -->
<!-- TemplateBeginRepeat name="Component.Fields.CallToAction" -->
@@GetComponent(Field,'CallToAction')@@
<@@CallToAction.Fields.Item.Key@@><![CDATA[@@CallToAction.Fields.Item.Content@@]]></@@CallToAction.Fields.Item.Key@@>
<!-- TemplateEndRepeat -->
</product>