Automatically Load Property Types as Dynamic Content

by: Allan Thræn

Dynamic Content is cool! Really cool. However, even good things can always get better. Back in october last year I wrote about how to automatically register dynamic content by attaching an attribute (like all other plugins in EPiServer) http://labs.episerver.com/en/Blogs/Allan/Dates/112230/10/Auto-Loading-of-Dynamic-Content/. Now, I’ve extended that project to also include auto registration of all the property types in EPiServer as Dynamic Content.

“Now, why would you do a crazy thing like that?”, you might wonder. The answer comes in two parts: a) I guess I don’t have a life, and b) I’ve noticed that as I grow more and more accustomed to Dynamic Content I’ve started to use it like I would use web parts. That means that I’ve been creating Dynamic Content (DC) wrappers for common EPiServer properties so editors can drag them around xhtml-fields and use them as building blocks.

Anyway, I figured the time was right for a generic way to include all the Property types as Dynamic Content. First, I used generics to create a “PropertyDC<PropertyType> : IDynamicContent” class, secondly I made sure that one of those were registrered upon startup for every Property Type in EPiServer CMS.

foreach (PageDefinitionType pdf in PageDefinitionType.List())
{
    //We now have a property type
        
    PropertyData pd=(pdf.TypeName==null) ?
        PropertyData.CreatePropertyDataObject(pdf.DataType)
        :
        PropertyData.CreatePropertyDataObject(pdf.AssemblyName, pdf.TypeName);
    
    
    Type basetype=typeof(PropertyDC<>);
    Type result = basetype.MakeGenericType(pd.GetType());
    AddNewDC("[Property] "+pdf.Name, result, pdf.TypeName);
}

 

Download the binary here (just drop it in the bin, to enable both the [DCPlugin()] attribute and the auto registration of property types).

Download full source here.

26 January 2009


Comments

  1. i am strugling arrounf dynamic content, problem is this when i palce dynamic content inside another dynamic content its not getting renderd, can u help plz
  2. Try to look at http://dynamiccontent.codeplex.com/ there should be source code there that enables you to have dynamic content within dynamic content (if you for instance use the XHTML Dynamic content.
Post a comment    
User verification Image for user verification  
Allan Thræn

About me

I am a product manager @ EPiServer, with a passion for the more geeky side of things. My technical interests are typically focused around user problems, user experience,  search, information management, artificial intelligence and  personalization

On top of this blog I have the blog Allan On Technology and I often crosspost.

DISCLAIMER: Unless otherwise stated in the posts, this blog expresses my personal opinions, experiments and views, not necessarilly the views of EPiServer AB.

 645 page views this week.

 

 

Syndications


Archive


Tag cloud

EPiTrace logger