Can i use model generated in AppData mode on another template
Hi,
Can I use models in AppData mode generated by models builder in another Document Type template?
What i am trying to do:
I have node News and his child News Item , where i want to create and update news programmatically but from another templates called Create News and Update News.
I have tried to inherit News Item model in Create News and Update news templates like this:
I'm not sure if I understand what you are wanting to do. It sounds like you want to present a news story in one of three formats. In this case you would have 3 views(templates) for each NewsItem. If you are wanting the newsitem to display in one of three ways, then you will need a Property on your newsitem to allow your code to know which way to display the newsitem. A bit of psuedocode below. Assume that News is the parent Document Type and NewsItem is the child. Your news.cshtml file might look like:
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.News>
@using ContentModels = Umbraco.Web.PublishedModels;
@{
//Partial view that can be palced on any skin.
Layout = null;
IPublishedContent theNews = GetNews();
}
<h1>News</h1>
@foreach(News itm in theNews)
{
switch(itm.NewsFormat)
{
case "Format1":
@Html.Partial("~/Views/Format1.cshtml", itm)
break;
case "Format2":
@Html.Partial("~/Views/Format2.cshtml", itm)
break;
case "Format3":
@Html.Partial("~/Views/Format3.cshtml", itm)
break;
default:
<div>No format Available for news</div>
break;
}
}
Can i use model generated in AppData mode on another template
Hi,
Can I use models in AppData mode generated by models builder in another Document Type template?
What i am trying to do:
I have node News and his child News Item , where i want to create and update news programmatically but from another templates called Create News and Update News.
I have tried to inherit News Item model in Create News and Update news templates like this:
and like this:
But its not working. What would be the best way to do this?
Would it be good solution to create 3 templates from same document type maybe?
I dont know what is the best practice to do it.
I'm not sure if I understand what you are wanting to do. It sounds like you want to present a news story in one of three formats. In this case you would have 3 views(templates) for each NewsItem. If you are wanting the newsitem to display in one of three ways, then you will need a Property on your newsitem to allow your code to know which way to display the newsitem. A bit of psuedocode below. Assume that News is the parent Document Type and NewsItem is the child. Your news.cshtml file might look like:
What the above code does is basically leverages the power of MVC partial views so that your data is separate from how it is presented. I believe that the following link kind of explains a bit of pre-requisite knowledge:https://our.umbraco.com/documentation/Tutorials/Creating-Basic-Site/Articles-Parent-and-Article-Items/
is working on a reply...