I got stuck on this so just some general information.
I needed to determine the type of what the Nested Content elements were. And based on the Umbraco 8 documentation for Nested Content, it was not clear, because I have multiple different types of nested content with different property values. That said, here is my solution.
It got the type by using ContentType.Alias
@{
var items = Model.Value<IEnumerable<IPublishedElement>>("homepageSections");
foreach (var item in items)
{
if (item.ContentType.Alias == "homepageArticles"){
//Show selected articles
}else if (item.ContentType.Alias == "homepageEvents"){
//Show selected articles
}else{}
}@*End foreach*@
}
I saw Paul Wright added the switch AND the 'item' being passed into the partial.
Of course the switch should be a cleaner choice.
Being that the example I originally had uses 'IPublishedElement' if you try to access the 'item' in the partial and you head looks something like this in your Partial
@inherits Umbraco.Web.Mvc.UmbracoViewPage
This this will not work because 'IPublishedElement' is not 'IPublishedContent' which is the error you will get if you try to use your partial.
That said in your partial view, you would get rid of or comment out the line
@inherits Umbraco.Web.Mvc.UmbracoViewPage
And instead use
@model IPublishedElement
Then your partial could look something like
@model IPublishedElement
@{
var item = Model;
<p>@item.Value("PageTitle")</p>
or
<p>@Model.Value("PageTitle")
@*so on and so forth*@
}
Since I am fairly new to the ways of the Umbraco 8, I thought I'd share some knowledge.
How to get determine the type in Nested Content
I got stuck on this so just some general information.
I needed to determine the type of what the Nested Content elements were. And based on the Umbraco 8 documentation for Nested Content, it was not clear, because I have multiple different types of nested content with different property values. That said, here is my solution.
It got the type by using ContentType.Alias
I am going to add onto this.
I saw Paul Wright added the switch AND the 'item' being passed into the partial.
Of course the switch should be a cleaner choice.
Being that the example I originally had uses 'IPublishedElement' if you try to access the 'item' in the partial and you head looks something like this in your Partial
This this will not work because 'IPublishedElement' is not 'IPublishedContent' which is the error you will get if you try to use your partial.
That said in your partial view, you would get rid of or comment out the line
And instead use
Then your partial could look something like
Since I am fairly new to the ways of the Umbraco 8, I thought I'd share some knowledge.
@Paul Wright or any other Umbracian
Now that I am in the partialview using the IPublishedElement as the Model. I had to remove the
Now that I did that, I keep not being able to get to the root node.
When I try to use
I get an error that Umbraco has no context. It says ContentAtRoot does not exist in Umbraco.
When I try to dot noate in Visual Studio, I just get the ".Web, .Mvc, .Core"
How would I get back out to the root node. I have a part of the code that needs to exist in that partial to get to the root node.
Found my solution.
Instead of using
You use.
is working on a reply...