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
I have a property on all document types headline and right now it is used in redundant code in two (could be more) view files:
Meta data partial view:
<title>@(Model.Value<string>("headline") != "" ? Model.Value("headline") : Model.Name)</title>
Different template views:
<h1>@(Model.Value<string>("headline") != "" ? Model.Value("headline") : Model.Name)</h1>
I am now trying to extend the Model so I can use Model.Value("PageTitle) / Model.PageTitle instead.
But I must admit that I can´t find out. I have done a lot og Razor in views, but not yet worked with my own custom classes i .NET nor Umbraco.
One thing I have found out, though: This doesn´t work (and also seems to be tied up on only the SiteHome document type)! :)
namespace Umbraco.Web.PublishedModels { public partial class SiteHome { public string PageTitle { get { return Model.Value<string>("headline") != "" ? Model.Value("headline") : Model.Name; } } } }
Hi Martin
You 'used' to be able to specify a base class for all your generated Modelsbuilder Models:
https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Control-Generation-vpre8_5#models-base-class
But I think this may have been removed from the Core version of Umbraco in version 8.5, and in order to do this you may require the external plugin:
https://github.com/dawoe/Zbu.ModelsBuilder
regards
Marc
Thanks. Can you point me in a direction with some code? I am newbie in working with classes. 🙂
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Extend Model with a property for all document types for use in all views
I have a property on all document types headline and right now it is used in redundant code in two (could be more) view files:
Meta data partial view:
Different template views:
I am now trying to extend the Model so I can use Model.Value("PageTitle) / Model.PageTitle instead.
But I must admit that I can´t find out. I have done a lot og Razor in views, but not yet worked with my own custom classes i .NET nor Umbraco.
One thing I have found out, though: This doesn´t work (and also seems to be tied up on only the SiteHome document type)! :)
Hi Martin
You 'used' to be able to specify a base class for all your generated Modelsbuilder Models:
https://our.umbraco.com/Documentation/Reference/Templating/Modelsbuilder/Control-Generation-vpre8_5#models-base-class
But I think this may have been removed from the Core version of Umbraco in version 8.5, and in order to do this you may require the external plugin:
https://github.com/dawoe/Zbu.ModelsBuilder
regards
Marc
Thanks. Can you point me in a direction with some code? I am newbie in working with classes. 🙂
is working on a reply...