[Solved] Creating Content Type in a dynamic Way

Topics: Customizing Orchard
Oct 23, 2012 at 8:46 PM

Hi,

I would like to create ContentType dynamically. Is it possible? I saw that there is a ContentTypeRecord class but I have no idea if I can use it to create a ContentType and How I can do it.

 

Thanks in advance.

Developer
Oct 23, 2012 at 10:38 PM

You can do it through Migrations?? i.e.

ContentDefinitionManager.AlterTypeDefinition("Thread", cfg => cfg
    .WithPart("ThreadPart")
    .WithPart("CommonPart")
);

That dynamically create a Thread ContentType

Oct 24, 2012 at 9:46 AM

But, In this way I need to have already the ContentType. Isn't it? Instead, I would like to create the contentType on module activation. If it is possible.

Thank you very much for the reply.

Developer
Oct 25, 2012 at 9:55 AM

When you call .AlterTypeDefinition("Thread"), it will create the content type if it doesn't already exist. Nick's example is exactly what you need when you implement it as part of a migration class.

Oct 25, 2012 at 10:22 PM

Ok, Thank you very much. It is exactly what I need. Thank you very much!

 

Bye!