Component Iterator Assistant

The Dreamweaver CIA or ComponentIteratorAssistant adds the following five function extensions to the Dreamweaver and can be used both in page-templates and in component-templates:

  1. TotalNumberOfComponentPresentations()
  2. IsFirstComponent(�)
  3. IsMiddleComponent(�)
  4. IsLastComponent(�)
  5. IsPreviewMode()

TotalNumberOfComponentPresentations()

This function returns the number of component-presentations on the page as an integer number.
Example 1: outputs the number of component-presentations in the page or component-template
@@TotalNumberOfComponentPresentations()@@

Example 2: test if the number of component-presentations are equal to a number
<!-- TemplateBeginIf cond = "TotalNumberOfComponentPresentations() == 2" -->
  �
<!-- TemplateEndIf -->

Example 3: test if the current component-presentation being rendered is second to last (in a page template)
<!-- TemplateBeginRepeat name="Components" -->
 <!-- TemplateBeginIf cond = "TemplateRepeatIndex == TotalNumberOfComponentPresentations()-2" -->
   �
 <!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->

The TemplateRepeatIndex starts counting from 0, so to test for the second to last component we need to compare it with the number of component-presentations minus two. The preferred way to test if the last component on the page is rendered is using the IsLastComponent(�) function.
Note the difference between the examples. To output the result of a function use the @@ placeholder as in @@TotalNumberOfComponentPresentations()@@. To use the result of a function in an expression just use the function name, as-in TotalNumberOfComponentPresentations().
Note that all are functions and the parenthesis () are mandatory.

Page Preview 2011

IsFirstComponent(�)

This function returns true if the first component-presentation on the page is rendered. This function needs the identifier (TCM ID as a string) of a component. In most cases the current component being rendered is passed as a parameter to this function.
Example 1: usage in a page template
<!-- TemplateBeginRepeat name="Components" -->
 <!-- TemplateBeginIf cond = "IsFirstComponent(Component.ID)" -->
   �
 <!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
Example 2: usage in a component template
<!-- TemplateBeginIf cond = "IsFirstComponent(Component.ID)" -->
 �
<!-- TemplateEndIf -->

This function IsFirstComponent(�) equals the same result as testing if the TemplateRepeatIndex == 0. However the preferred way is using this high-level function abstraction. The reason is that the TemplateRepeatIndex is only available in a page-template and not in a component-template, the IsFirstComponent(�) function is available in both templates. It also prevent mistakes which are simple to make but hard to solve.
Note that the mandatory parameter is by-design. It allow you to pass the TCM ID of (another/different) component and test if that one is the first component on the page.

IsMiddleComponent(�)

This function returns true if the middle component-presentation on the page is processed. Since it can only be the middle component if there is both a first and last component, this function returns false if the number of component-presentations is less than three. This function needs the identifier (TCM ID as a string) of the (current) component being rendered.
Example 1: usage in a page-template
<!-- TemplateBeginRepeat name="Components" -->
 <!-- TemplateBeginIf cond = "IsMiddleComponent(Component.ID)" -->
   �
 <!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
Example 2: usage in a component-template
<!-- TemplateBeginIf cond = "IsMiddleComponent(Component.ID)" -->
 �
<!-- TemplateEndIf -->

IsLastComponent(�)

This function returns true if the last component-presentation on the page is active. This function needs the identifier (TCM ID as a string) of the current component being rendered.
Example 1: usage in a page-template
<!-- TemplateBeginRepeat name="Components" -->
 <!-- TemplateBeginIf cond = "IsLastComponent(Component.ID)" -->
   �
 <!-- TemplateEndIf -->
<!-- TemplateEndRepeat -->
Example 2: usage in a component-template
<!-- TemplateBeginIf cond = "IsLastComponent(Component.ID)" -->
 �
<!-- TemplateEndIf --> 

Page Preview

IsPreviewMode()

This function returns true if the page is previewed or if a single component-presentation on the page is previewed. This function returns false if the page is published.
Examples:
<!-- TemplateBeginIf cond = "IsPreviewMode()" -->
 �
<!-- TemplateEndIf -->

or
<!-- TemplateBeginIf cond = "!IsPreviewMode()" -->
 �
<!-- TemplateEndIf -->
This function is added to support cases when it is not possible to determine the number of component-presentations on the page. This happens when a single component-presentation is previewed, the functions IsFirstComponent, IsMiddleComponent or IsLastComponent returns false, and the function TotalNumberOfComponentPresentations fails and return -1. The IsPreviewMode() function allows you to take control in those situations.

Component Presentation Preview

Installation of the Dreamweaver CIA

Step 1: Copy the �Tridion.Extensions.Templating.ComponentIteratorAssistant.dll� to the �C:\Windows\assembly\� directory. Or use the gacutil.exe tool to add the DLL to the assembly cache via the command-line (gacutil.exe is also installed in the directory �C:\Windows\Microsoft.NET\Framework\v1.1.4322\�):
"c:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe" /i Tridion.Extensions.Templating.ComponentIteratorAssistant.dll

Step 2: Make a backup of the �c:\Program Files\Tridion\config\Tridion.ContentManager.Config� file and then edit the orginal file and add the following line as the last line within the <functionSources> element.
<functionSource type="Tridion.Extensions.Templating.ComponentIteratorAssistant.CustomFunctions" assembly="Tridion.Extensions.Templating.ComponentIteratorAssistant, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=8e71968b58f92d6b"/>
After you have done this the result should look like as following:
<functionSources>
 <functionSource � />
 <functionSource
 type="Tridion.Extensions.Templating.ComponentIteratorAssistant.CustomFunctions"
 assembly="Tridion.Extensions.Templating.ComponentIteratorAssistant,
  Version=1.0.0.0,
  Culture=Neutral,
  PublicKeyToken=8e71968b58f92d6b"/> 
</functionSources>

Tridion.ContentManager.Config

Step 3:  use the �Component Services� application to restart the COM+ application �SDL Tridion Content Manager�. If the Template Builder is open, close it and restart the Template Builder.

Step 4: test by adding some CIA functions to a page or component-template.


Developer
Company
:    HintTech
License agreement
Download package
Tags
:    dreamweaver,  CIA,  expression language,  template,  custom function
Version
:   1.0
Source
:   Yes

About the Author
Walter van der Heiden
Solutions architect

Walter van der Heiden is a Solutions Architect at HintTech in Delft (Netherlands) where he has been working since 2003. He has more than 10 years of experience with the implementation of SDL Tridion products both in Java and .NET environments.

HintTech

Most Popular Building Blocks

These are the most popular Building Blocks. Did you already get them?