Showing posts with label Function Sources. Show all posts
Showing posts with label Function Sources. 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")@@