Showing posts with label Dreamweaver templates. Show all posts
Showing posts with label Dreamweaver templates. Show all posts

Tuesday, September 04, 2012

Dreamweaver expressions and JScript

As a followup on my previous post:

The response from CollectionLength is a string value, and this will cause problems when you need to perform calculations with the number.

The solution to this problem is JScript. What not many people know is that the expression between @@<code>@@ or ${<code>} is evaluated as JScript, and this will allow you to use methods like parseInt:

@@parseInt(${CollectionLength("[multi-value field name]")})@@

Tuesday, August 21, 2012

Counting a collection in Dreamweaver Templates


Many times in your Dreamweaver Template you want to count the number of field values of a multivalued field, or the number of Components in an array.

There is a way to count a collection in the Package, but the documentation regarding the built-in functions available within Dreamweaver templates is not very extensive.
Before you start writing a .NET Template that counts a collection and pushes this number into a Package Item, take a look at:
[TemplateCallable]
public int CollectionLength(string expression)

The expression passed to the method equals the fully qualified name of the Package Item and a value selector.
The following example will return the number of values of the paragraphs field.
@@CollectionLength("Component.Fields.paragraphs")@@

Saturday, November 19, 2011

Getting the TemplateRepeatIndex of an outer repeating region

When you need the TemplateRepeatIndex of an outer repeating region you can use the following code snippet:


@@Push("OuterTemplateRepeatIndex", ${(TemplateRepeatIndex == 0) ? (parseInt(OuterTemplateRepeatIndex) >= 0) ? parseInt(OuterTemplateRepeatIndex) +1 : 0 : parseInt(OuterTemplateRepeatIndex)})@@



Each time the TemplateRepeatIndex == 0 the OuterTemplateRepeatIndex will be increased with 1, unless it is not set, then I default to 0. For any other value of TemplateRepeatIndex I will reset the OuterTemplateRepeatIndex with itself.


(...)

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