In umbraco 7 i used the code below to include partials based on whatever nested content was chosen in a particular document type. However i am struggeling to figure out how to do the same on Umbraco 8.
Is it possible to get the Document Type Alias of nested content in Umbraco 8?
var modules = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("modules");
foreach (var module in modules)
{
@Html.Partial("~/Views/Partials/Modules/" + module.DocumentTypeAlias + ".cshtml", module)
}
Thanks alot, that did the trick :D
Some how i missed that property when going through the documentation.
However i hit another snag i hope someone might be able to help with.
After i got the partial included, i cant seem to get the "module" variabel to parse through to the partial.
When i try i get an error telling me "The name 'module' does not exist in the current context"
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
Layout = "master.cshtml";
}
@* the fun starts here *@
<div role="main" class="main">
@{
var modules = Model.Value<IEnumerable<IPublishedElement>>("contentclass");
foreach (var module in modules)
{
@Html.Partial("~/Views/Partials/Modules/" + module.ContentType.Alias + ".cshtml", module)
}
}
</div>
Umbraco 8 DocumentTypeAlias
Hi
In umbraco 7 i used the code below to include partials based on whatever nested content was chosen in a particular document type. However i am struggeling to figure out how to do the same on Umbraco 8.
Is it possible to get the Document Type Alias of nested content in Umbraco 8?
Hi Esben
Sure, in Umbraco 8 there is no longer a
DocumentTypeAlias
property onIPublishedContent
, but just aContentType
property, which has anAlias
property.So something like this should work:
If you are using Nested Content you're working with element types, which is based on
IPublishedElement
: https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Core/Models/PublishedContent/IPublishedElement.cs#L16where
IPublishedContent
inherit fromIPublishedElement
and therefore share the same based properties: https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Core/Models/PublishedContent/IPublishedContent.cs#L13So with Nested Content this should work.
/Bjarne
Thanks alot, that did the trick :D Some how i missed that property when going through the documentation.
However i hit another snag i hope someone might be able to help with.
After i got the partial included, i cant seem to get the "module" variabel to parse through to the partial. When i try i get an error telling me "The name 'module' does not exist in the current context"
Partial Code:
Hi Esben
The default model for UmbracoViewPage is IPublishedContent, so you have to specify that your model is IPublishedElement.
Instead of writing
@inherits Umbraco.Web.Mvc.UmbracoViewPage
you can write@inherits Umbraco.Web.Mvc.UmbracoViewPage<IPublishedElement>
I have already tried that and unfortunatly the issue is the same with or without:
If i copy the code from the included partial into the main code instead of using a partial, everything works as expected.
Ah sorry, didn't see you were using
module
in your partial view. It should beModel
. In other words, instead ofyou should write
... i hadn't even seen that myself. Maybe its time to get glasses :D
That solved the problem, Thanks alot for the help
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.