Hi,
I'm trying to figure out how to deal with custom item types and there's one thing that seems really, really weird.
Let's say that I have this simple type defined as a code-first item. All the permissions are set up too in admin, I have a layout for it and I can add it to the page. So far so good.
[Item("Hero Component", "")] [Category("MyAwesomeShop")] [ModuleAttachmentRule(true), StructureRule(StructureContextType.Paragraphs)] public class HeroModel : ItemEntry { [Name("Title")] [Required] public string Title { get; set; } [Name("Call to action link")] [Link] [Required] public string CTALink { get; set; } }
Layout file is the werid part. And how I can get the actual values of that model class specifically.
So for example, for this oversimplified example, it should look like this, right?
@inherits Dynamicweb.Rendering.ViewModelTemplate<Dynamicweb.Frontend.ParagraphViewModel> <div class="hero"> <h1>@Model.Item.GetString("Title")</h1> <a href="@Model.Item.GetLink("CTALink").Url">CTA</a> </div>
Now, am I missing something here? How is this possible that I am defining a specific model class and then on the template I don't have any access to that type and I need to use a bunch of magic strings and methods to get properly types values? So goodbye intellisense, goodbye refactorings, goodbye "find usages" for my properties. But welcome magic strings, typos, casting errors and maintenance hell since everything is accessed by a string?
Is this really the correct approach? Is there a way to get an instance of the actual HeroModel class on the template so I could write something like @model.CTALink?