简体   繁体   English

Tridion:循环链接组件时的组件模板问题

[英]Tridion: Component Template issue when looping over linked components

Hello, I got a problem with looping over my linked component. 您好,我在循环链接组件时出现问题。
I created a EmailSetup(View UML diagram ) Component with a product item. 我创建了一个带有产品项的EmailSetup(View UML图 )组件。
The product Component has schema (EmailBlockWithCode). 产品Component具有架构(EmailBlockWithCode)。
Product: 产品:

  • - Code = "wms_III" - Code =“wms_III”
  • - Item: - 项目:
    • - Key = "ProductKey" - Key =“ProductKey”
    • - Content = "ProductContent" - Content =“ProductContent”
    • - CallToAction : - 呼吁采取行动 :
    • - Item: - 项目:
      • - Key = "BluetoothKey" - Key =“BluetoothKey”
      • - Content = "BluetoothContent" - Content =“BluetoothContent”

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 这是函数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. 在'item'(key = ProductKey; content = ProductContent)上我找到了一个函数IteratingOverMultivalueEmbeddedFields,但这也不会循环我的产品。 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 -->


UML diagram UML图

So it looks like you can't access the components in the package after your DW function pushes them in? 因此,在DW函数将它们推入后,您似乎无法访问包中的组件?

With the DGX , your code would be approximately like this, have you considered using it instead? 使用DGX ,您的代码将大致如此,您是否考虑过使用它?

<products>
    <!-- TemplateBeginRepeat name="Component.Fields.Product" -->
    <product name="@@Get('Fields.Product[${TemplateRepeatIndex}].Code')@@">   
      <!-- TemplateBeginRepeat name="Product.Fields.Item" -->
        <@@Get('Fields.Product[${TemplateRepeatIndex}].Fields.Item.Key')@@><![CDATA[@@Get('Fields.Product[${TemplateRepeatIndex}].Fields.Item.Content')@@]]></@@Get('Fields.Product[${TemplateRepeatIndex}].Fields.Item.Key')@@>
      <!-- TemplateEndRepeat -->
      <!-- TemplateBeginRepeat name="Product.Fields.CallToAction" -->
        <@@Get('Fields.CallToAction[${TemplateRepeatIndex}].Fields.Item.Key')@@><![CDATA[@@Get('CallToAction[${TemplateRepeatIndex}].Fields.Item.Content')@@]]></@@Get('Fields.CallToAction[${TemplateRepeatIndex}].Fields.Item.Key')@@>
      <!-- TemplateEndRepeat -->    
    </product>
    <!-- TemplateEndRepeat -->
</products>

This has probably something to do with how the template is executed. 这可能与模板的执行方式有关。 The most inner repeating regions are rendered first, and then the renderer works its way outwards. 首先渲染最内部重复区域,然后渲染器向外移动。

So in the inner repeating region you don't have access yet to the component you get earlier. 因此,在内部重复区域中,您无法访问之前获得的组件。

Yes, this is not intuitive at all, but that's how it works. 是的,这根本不直观,但这就是它的工作原理。

What you can do is go through all linked components and push them into the package using the field name in a .NET TBB which is executed before the DWT. 你可以做的是浏览所有链接的组件,并使用在DWT之前执行的.NET TBB中的字段名称将它们推入包中。

http://80000ft.blogspot.nl/2011/09/render-order-of-repeating-regions-and.html http://80000ft.blogspot.nl/2011/09/render-order-of-repeating-regions-and.html

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: 并且renderComponentPresentation加载另一个dwt:

 <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>  

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

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