I’m coming from the Optimizely/Episerver world, where we’re used to defining page types and blocks in C# and treating the codebase as the source of truth for the content model.
I’m trying to understand the recommended Umbraco approach to this.
Ideally, I’d like to be able to create a completely fresh database, start the application, and have all Document Types, Element Types/blocks, properties, etc. recreated from definitions in source control.
From what I understand, Models Builder works in the opposite direction — the Document Types are defined in Umbraco and C# models are generated from them.
Is there a commonly used code-first approach in Umbraco, or is the recommended solution to define the schema in the backoffice and use something like uSync to keep it in source control?
I’d be interested to hear how teams coming from a code-first CMS such as Optimizely usually approach this.
You are correct, models builder works in the other direction and you specify the document/element types in the CMS and this generates the models. Make sure you install uSync first, as this will generate the sync files that you can use to deploy these through your environments.
You will need to set the ModelsMode to SourceCodeAuto in appSettings.json to generate C# files on disk.
So, for the models, the source of truth is Umbraco, but for everything else it would be code which you would commit to your repo like any other .NET app.
See here for the docs on Models Builder:
I would recommend watching Paul Seal’s video series if you want to learn more about getting start with Umbraco:
This is for Umbraco 13, so the UI looks different and there may be a few other minor differences, but ultimately the same concepts apply.
There’s also the official docs here:
If you have any question, just ask away on the forum - we are a friendly community so we like to help!