Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hello, I would like to add my extension method to the generated models using Model Builder. Is it possible in Umbraco 13?
Example
This is the default generated code for my property using Model Builder.
public virtual string Testtest => this.Value(_publishedValueFallback, "testtest");
But I want to generate the model property using Model Builder with my extension method like,
public virtual string Testtest => this.GetValueWithLanguage(_publishedValueFallback, "testtest");
create a new partial class like below
namespace Umbraco.Cms.Web.Common.PublishedModels { public partial class ModelToExtend { [ImplementPropertyType("Testtest")] public virtual string Testtest => this.GetValueWithLanguage(this._publishedValueFallback, "testtest"); } }
replace ModelToExtend with the class generated by modelsbuilder
Hello Huw Reddick,
Thank you for your assistance.
If I create a new partial class and replace it with a generated class, I lose my changes when generated the next time.
I want to automatically replace this.Value with this.GetValueWithLanguage extension method whenever generating the class from the model builder.
You are not replacing the generated class, the new partial class is to extend the generated partial class
I found the solution for customizing the generated models by using the 'IModelsGenerator' interface.
We create our own 'CustomModelsGenerator.cs' class, which should be inherited with the 'IModelsGenerator' interface.
https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/templating/modelsbuilder/understand-and-extend#imodelsgenerator
It is working as expected for my business needs.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Umbraco 13 customize the generated models while generating models via Model builder
Hello, I would like to add my extension method to the generated models using Model Builder. Is it possible in Umbraco 13?
Example
This is the default generated code for my property using Model Builder.
public virtual string Testtest => this.Value(_publishedValueFallback, "testtest");
But I want to generate the model property using Model Builder with my extension method like,
public virtual string Testtest => this.GetValueWithLanguage(_publishedValueFallback, "testtest");
create a new partial class like below
replace ModelToExtend with the class generated by modelsbuilder
Hello Huw Reddick,
Thank you for your assistance.
If I create a new partial class and replace it with a generated class, I lose my changes when generated the next time.
I want to automatically replace this.Value with this.GetValueWithLanguage extension method whenever generating the class from the model builder.
You are not replacing the generated class, the new partial class is to extend the generated partial class
I found the solution for customizing the generated models by using the 'IModelsGenerator' interface.
We create our own 'CustomModelsGenerator.cs' class, which should be inherited with the 'IModelsGenerator' interface.
https://docs.umbraco.com/umbraco-cms/v/13.latest-lts/reference/templating/modelsbuilder/understand-and-extend#imodelsgenerator
It is working as expected for my business needs.
is working on a reply...