0
votes

Exploring Umbraco 8 and playing around building a test site etc.

Building document types and content pages via the back office interface, and looking in the code itself I've noticed a files called models.generated.cs.

looking inside, it contains partial classes like public partial class AndyTestPage : PublishedContentModel { } and properties I've given it like [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder", "8.5.5")] [ImplementPropertyType("andyProperty1")] public string AndyProperty1 => this.Value<string>("andyProperty1");

my question is, what exactly is the point of this file? what does is do and how are these properties and classes created in here via the backoffice cms.

second question is, how would I go about creating a document type, and properties from code? my noob assumption is to simply add the classes in the this file, but that doesnt seem right?

Thanks,

Andy

2

2 Answers

0
votes

It belongs to modelbuilder. It depends on how you build your umbraco solution. If you use visual studio you can use something called strongly type, it helps building templates with VS. By default, modelsbuilder is set to "PureLive", which is for users who builds within the umbraco backoffice system. You can set modelsbuilder to different options, depending on how you build. You should not edit the file, it is created and maintained by the system.

https://umbraco.tv/videos/umbraco-v7/implementor/working-with-umbraco-data/working-with-models-builder/

https://our.umbraco.com/documentation/reference/templating/modelsbuilder/

0
votes

elitenet.dk has answered the first question

With regards to your second question Umbraco is database/content first so unfortunately you cant write documenttypes etc. from code first... not that i know of.

I beleive this is because Umbraco was designed to be used by almost anyone with a little html/css knowledge. E.g. You can create templates and views from the cms without having to know anything about serverside development.

Just a little tip if youre starting with Umbraco and plan on using multiple environments take a look at Kevin Jumps Usync package, essentually the package allows for document types/properties etc. to be pushed from environment to environment.Usync