Understand and Extend
Understanding and Extending ModelsBuilder in Umbraco
Models Generation Process
/// <summary>TextPage</summary>
[PublishedModel("textPage")]
public partial class TextPage : PublishedContentModel
{
//static helpers
public new const string ModelTypeAlias = "textPage";
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
public new static IPublishedContentType GetModelContentType(IPublishedContentTypeCache contentTypeCache)
=> PublishedModelUtility.GetModelContentType(contentTypeCache, ModelItemType, ModelTypeAlias);
public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedContentTypeCache contentTypeCache, Expression<Func<Page, TValue>> selector)
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(contentTypeCache), selector);
private IPublishedValueFallback _publishedValueFallback;
//constructor
public TextPage(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
: base(content, publishedValueFallback)
{
_publishedValueFallback = publishedValueFallback;
}
// properties
///<summary>
/// Header
///</summary>
[ImplementPropertyType("header")]
public virtual string Header => this.Value<string>(_publishedValueFallback, "header");
}Composition and Inheritance
Composition
Inheritance
Extending Models
Custom Model Generation with IModelsGenerator
Best Practices for Extending Models
Good practices
Bad practices
Ugly practices
Last updated
Was this helpful?