EPiServer  /  CMS September 17, 2010

How to add a LinkItemCollection property using Page Type Builder

Every now and then, often on Twitter, I get asked how to add a property of type LinkItemCollection to a page type using Page Type Builder. First of all, the solution is to use the PageTypeProperty attribute and specify the type of the property to be PropertyLinkCollection. The return type should be LinkItemCollection. Like this:

[PageTypeProperty(Type = typeof (PropertyLinkCollection)]
public virtual LinkItemCollection Links { get; set; }

More generally, when you use Page Type Builder you can use any type of EPiServer properties, including third party properties and your own custom properties. However, when you do so you must explicitly specify the type of (EPiServer) property that the (code) property should be mapped to, just like we did in the example above.

When you create properties of the standard (“system”) property types, such as PropertyNumber or PropertyBoolean that isn’t necessary as Page Type Builder will infer the property type from the code property’s return type. You can find a list of these default mappings in this post.

Of course, code properties of type LinkItemCollection could, and should, also be mapped to PropertyLinkCollection by default and I’ll fix that in the next release.

PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.

Joel Abrahamsson

Joel Abrahamsson

I'm a passionate web developer and systems architect living in Stockholm, Sweden. I work as CTO for a large media site and enjoy developing with all technologies, especially .NET, Node.js, and ElasticSearch. Read more


comments powered by Disqus

My book

Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!

More about EPiServer CMS