Views: 3292
Number of votes: 3
Average rating:

CMS7 programmatically create dynamic property

Haven’t used dynamic properties in a long while, but yesterday when building an external module I thought that a dynamic content reference property would be perfect for my needs.

But I wanted to create it programmatically so the deployment would only be copying of files.

I only found a blog post for CMS6. Lucky for me it wasn’t to much that differed. CMS7 code below:

private void SetupDynamicProperty()
  var TabDefinitionRepository = ServiceLocator.Current.GetInstance<ITabDefinitionRepository>();
  var PropertyDefinitionTypeRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionTypeRepository>();
  var PropertyDefinitionRepository = ServiceLocator.Current.GetInstance<IPropertyDefinitionRepository>();
    PropertyDefinition pd = new PropertyDefinition();
    pd.ContentTypeID = 0; // 0 == Dynamic property
    pd.Name = "YourPropertyName;
    pd.EditCaption = "HandbookStartPage";
    pd.Type = PropertyDefinitionTypeRepository.Load(4); // 4 == PageReference
  catch { }
Jul 20, 2014

Oskar Zetterberg
(By Oskar Zetterberg, 7/29/2014 12:14:49 PM)

For people wanting the CMS 6 solution here is the blog post mentioned above,

Arve Systad
(By Arve Systad, 8/4/2014 2:49:16 PM)

One should probably be a bit careful by using Dynamic properties in new CMS 7/7.5 projects though - I have a strong impression that dynamic props will disappear in the not too distant future to be replaced by inline usage of content elements (blocks, pages, products, media, you name it).

(By per.nergard, 8/11/2014 5:12:07 PM)

@Arve: Im not so sure that dynamic properties will be disappear. You are probably thinking of Dynamic Content in the XHTML editor.

Marc Erickson Legaspi
(By Marc Erickson Legaspi, 4/15/2015 12:53:13 PM)

Hi Per,

Where can I call SetupDynamicProperty() method?


Please login to comment.