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")@@

1 comment:

Anonymous said...

Just wanted to let you know that I found your page on and even though I liked
reading your article, it seems your blog acts up in a couple browsers.
If I use Firefox, it loads correctly, but if I use Chrome, it
pulls up looking overlapped and off-kilter. I simply wanted to offer you with
a quick bit of info, that's all.

Here is my web page - schuften