1

I could easily create a new entity inheriting from Sdl.Web.Common.Models.Teaser but those fields would not be available throughout the code base, only to templates which use my new entity.

I'm hoping to avoid editing the core files (under Sdl.web* namespace).

3

You can add your own "Entity" ExtendedTeaser, or something like that. You won't need to edit the core, simply make sure that the [new] fields in the schema are properly mapped to the members (properties) in your new class.

You don't need to touch the code base, you can create the Model in your own project: Jonathan.Primmer.Models.MyTeaser which extendes from Sdl.Web.Commons.Model.Teaser.

The Controller should process your model automatically. You need to use the appropriate Model in your view, though, and add your project as a reference to the Core DXA web project, so it can "see" your models. You will have to register the Class in the CoreAreaRegistration.cs file. If you don't have this file, then adding the right Model in the view is enough to resolve the appropriate class.

In fact you should be able to use the "old" Teaser class if you don't need the new fields.

2
  • Thanks Jaime, this was the approach I also had in mind, however, would the new fields be available to all usages of the original 'Teaser' entity? – Jonathan Primmer Jun 26 '15 at 16:29
  • The DXA model mapping code instantiates the model type registered for the View. For a view with registered model type Teaser will get a Teaser, not your subclass. If you want to use the properties of your subclass in a View, you will have to register your subclass instead of Teaser. – Rick Pannekoek Jun 26 '15 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.