Try our conversational search powered by Generative AI!

Is there a way to add properties to content types programmatically?


I have a scenario where I want to extend an existing content type, but do not have access to its code to extend it. Is there a way to add properties programmatically to that content type? I do have access to its view so I can use that new property, but not the code of the block.

Dec 01, 2021 19:24

A bit of an odd case but you can probably look into how a property is stored when added manually in Admin Mode and use similar code in a "late" dependant Initialization Module. Then use the dictionary in the view, ContentData["NewProperty"] or something like that should work.

If possible it's a lot cleaner to inherit the original "closed source" content type and convert existing blocks to the new type that has more properties.

Dec 01, 2021 21:52

I was hoping to avoid subclassing, it creates a lot of work for my editors, and adds a duplicate content type to library. I was hoping someone knew of the specific service to use internally to add those properties to the data definition. And be able to do advanced things like selection feeds and attributes as well. If the admin can do it, there must be a way for me to do it I think.

Dec 01, 2021 22:32
Johan Kronberg - Dec 02, 2021 6:29
The first part of my answer then... It's easy to use some tool (like dotPeek) via the admin mode aspx and see how the "manual" property saving works.

I found a way to do this reliably after poking through the decompiled code used in the content types admin pages. Was a lot easier than I thought it would be. I will post a followup with code examples on this shortly.

Jan 06, 2022 20:18

Here is another option that also gives you the ability to use typed properties in your views. Not tested in CMS 12 though, but as far as I can see, there has been no changes to the service that I'm extending in this example:

Edited, Jan 07, 2022 9:30
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.