Try our conversational search powered by Generative AI!

Per Nergård
Jul 20, 2014
  4163
(3 votes)

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>();
  try
  {
    PropertyDefinition pd = new PropertyDefinition();
    pd.ContentTypeID = 0; // 0 == Dynamic property
    pd.Name = "YourPropertyName;
    pd.EditCaption = "HandbookStartPage";
    pd.Type = PropertyDefinitionTypeRepository.Load(4); // 4 == PageReference
    propertyDefinitionRepository.Save(pd);
  }
  catch { }
}
Jul 20, 2014

Comments

Oskar Zetterberg
Oskar Zetterberg Jul 29, 2014 10:14 AM

For people wanting the CMS 6 solution here is the blog post mentioned above, http://blog.sigma.se/en/Development/Oskar-Zetterberg/Dates/2014/1/Create-dynamic-properties-programmatically/

Arve Systad
Arve Systad Aug 4, 2014 12:49 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).

Aug 11, 2014 03:12 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
Marc Erickson Legaspi Apr 15, 2015 10:53 AM

Hi Per,

Where can I call SetupDynamicProperty() method?

Thanks.

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog

The A/A Test: What You Need to Know

Sure, we all know what an A/B test can do. But what is an A/A test? How is it different? With an A/B test, we know that we can take a webpage (our...

Lindsey Rogers | Apr 15, 2024

.Net Core Timezone ID's Windows vs Linux

Hey all, First post here and I would like to talk about Timezone ID's and How Windows and Linux systems use different IDs. We currently run a .NET...

sheider | Apr 15, 2024