Monday, September 26, 2011

Pushing Component Presentations into the Package

When you use a .NET TBB to create a Component Presentations array, use the ComponentArray Package Item ContentType, rather than the expected ComponentPresentationsArray type:
Item pageRegionCPsItem = this.m_Package.CreateStringItem(ContentType.ComponentArray, ComponentPresentationList.ToXml(regionCPs));
this.m_Package.PushItem(String.Concat(this.itemNamePrefix, "_ComponentPresentations"), pageRegionCPsItem);
<!-- TemplateBeginRepeat name="MiddleTile_ComponentPresentations" -->
    @@RenderComponentPresentation()@@
<!-- TemplateEndRepeat -->
When you do use the ComponentPresentationsArray then either only the first element is rendered, or none at all.

Saturday, September 24, 2011

${..} and @@..@@ runtime

Rather than a line by line execution it seems that within a region all ${..} expressions are resolved first, before the rest of the TEL is executed. This makes the following impossible:
@@Push(“TabIndex”, TemplateRepeatIndex)@@
@@Push(“TabId”, “Tab${TabIndex}”)@@
When ${TabIndex} is being resolved, the function source call to push this Item into the Package is not executed yet.

Render order of repeating regions and conditional blocks


While developing modular templates you will always come across Dreamweaver templates. Since I’ve re-joined Tridion 3 months ago I learned a thing or two that are not documented and should benefit the community. So, here it is! My first blogpost.

Dreamweaver templates are rendered outside in. This means that the deepest repeating regeons and conditional blocks are rendered first, and that the mediator works its way from there to the top.

The result of this is that the following will not work. Both the TabIndex Package Item as the calls to RenderComponentField will return an empty string.


<!-- TemplateBeginRepeat name="Component.Fields.tabs" -->

  @@Push("TabIndex", TemplateRepeatIndex)@@

  <div id="tab@@TabIndex@@">

    <!-- TemplateBeginRepeat name="Field.subtabs" -->

      @@Push(“SubtabIndex”, TemplateRepeatIndex)@@

      <div id="tab@@TabIndex@@_subtab@@SubtabIndex@@">

        <h1>@@RenderComponentField(“tabs[${TabIndex}].subtabs[${SubtabIndex}].title”,
0)@@</h1>

        <p class=”introduction”>

          @@RenderComponentField(“tabs[${TabIndex}].subtabs[${SubtabIndex}].introduction”,
0)@@</p>

      </div>

    <!-- TemplateEndRepeat -->

  </div>

<!-- TemplateEndRepeat -->

When the subtab is being rendered all mark-up in the outer repeating region is not touched yet and therefore the TabIndex Item is not pushed into the Package either.

You can work around this by using the FieldPath Item pushed into the package during runtime. This Item is (as far as I know) not documented but can be very useful.

While rendering the 3rd subtab of the second tab that path will be “tabs[1].subtab[2]”.
To solve this issue you can use the following approach:

@@RenderComponentField(FieldPath + “.title”, 0)@@
Also, for cases you do need the Parent Template Repeat index I’ve developed a Function Source that extracts the index from the FieldPath:


Download: Index Functions - Function Source