Kentico Developer Issue 3

Page 42

42 Tips and Tricks

Matthew Lee @seanbun matthew.lee@kenticodeveloper.com

Tips and Tricks Most people don’t realise that the Kentico repeater web part can be nested to satisfy complex requirements. In his latest Tips and Tricks, Matt takes us through what this means and how it works. The repeater is one of the most frequently used webparts in Kentico, allowing for the retrieval of structured data in a logical, ordered manner without the need for c# code, or T-SQL. It traverses the CMS tree from a given path looking for documents of a given document type, and for each that satisfies a set of given conditions, repeats a given transformation. For example, we may want to return only the author, title, and date of publication, formatted nicely (transformation) for any blog post (document type), article (document type), or press release (document type), published before the year 2000 (condition). This can be accomplisehed without a single line of c# code, or a single line of T-SQL, using a repeater. Every now and then though we come across a more complex example, and although a simple repeater may not satisfy the needs of this more complex example, a nested repeater may.

Nested Repeaters A nested repeater is basically made up of a parent repeater which iterates through a set of documents, and a child repeater which executes once for each iteration of the parent repeater. Imagine it this way, a parent repeater loops through a set of books, while a child repeater loops through the pages of each book, with the result being the content of all books.

A Worked Example The concept is best demonstrated by introducing a worked example. My sample bookshop project contains two document types - Book and Author, with the details of each as follows. A book is made up of a Title, a Description, a Publisher, and a Year of Publication. An author is made up of a First name, and a Last name. A book may have more than one Author, and an Author is added as a child node of a Book.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.