I have a home page with a picture carousel. My intention was to create Document Type that would hold a dynamic list of pictures to be added. I know I can create an image list that can take multiple images.
But the carousel should also have header and description for each image. My approach was therefore to create a data structure with a compisition Document Type without a template named CarouselImage.
I then tried to add it to Home page as a sublist but quickly realized this was a bad idea as all sub pages related to Home page now was turning up in the same list.
I then created a new composite Document Type named CarouselList. I added CarouselImage as allowed sub item and made CarouselList to be displayed as a List View. The CarouselList was added to Home Document Type as a composition. I hoped this would display a ListView on my Home page. But the composition tab is empty.
Am I on the wrong track? Is it not posssible to create Document Types with custom sub lists?
Thanks Dave!
Excellent suggestion. It works fine to create type and use it in designer.
However I fail to retrieve the properties from nested type, but that might just be a beginners mistake with the umbraco models ...
This is my attempt:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
var home = Model.Content.Site() as ContentModels.Home;
}
@if (home.Images.Count() > 0)
{
foreach (var image in home.Images)
{
var carouselPicture = image as UmbracoTemplatePage<ContentModels.CarouselPicture>;
<div>@carouselPicture.header</div>
}
}
This fails with the following message:
CS1061: 'Umbraco.Web.Mvc.UmbracoTemplatePage<Umbraco.Web.PublishedContentModels.CarouselPicture>' does not contain a definition for 'header' and no extension method 'header' accepting a first argument of type 'Umbraco.Web.Mvc.UmbracoTemplatePage<Umbraco.Web.PublishedContentModels.CarouselPicture>' could be found (are you missing a using directive or an assembly reference?)
But I know my nested type has a property named header.
@inherits Umbraco.Web.Mvc.UmbracoViewPage
@{
var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("images");
foreach (var item in items)
{
<div>@item.GetPropertyValue("header")</div>
}
}
But I am slightly confused here. What is the difference with UmbracoTemplatePage and UmbracoViewPage? One seems to be typed and one dynamic? If so I prefer typed.
The designer obviously created my initial content as a UmbracoTemplatePage so I guess that is the new prefrerred way. Could I modify my code to fit in a UmbracoTemplatePage?
Nested composition Document Types with List View?
I just installed Umbraco 7.10.4.
I have a home page with a picture carousel. My intention was to create Document Type that would hold a dynamic list of pictures to be added. I know I can create an image list that can take multiple images.
But the carousel should also have header and description for each image. My approach was therefore to create a data structure with a compisition Document Type without a template named CarouselImage.
I then tried to add it to Home page as a sublist but quickly realized this was a bad idea as all sub pages related to Home page now was turning up in the same list.
I then created a new composite Document Type named CarouselList. I added CarouselImage as allowed sub item and made CarouselList to be displayed as a List View. The CarouselList was added to Home Document Type as a composition. I hoped this would display a ListView on my Home page. But the composition tab is empty.
Am I on the wrong track? Is it not posssible to create Document Types with custom sub lists?
Is there an alternative solution?
Hi Jakob,
I think what you are looking for is nested content : https://our.umbraco.org/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content
Dave
Thanks Dave! Excellent suggestion. It works fine to create type and use it in designer. However I fail to retrieve the properties from nested type, but that might just be a beginners mistake with the umbraco models ...
This is my attempt:
This fails with the following message:
But I know my nested type has a property named header.
I found this page on nested content: https://our.umbraco.org/documentation/getting-started/backoffice/Property-Editors/Built-in-Property-Editors/Nested-Content
So I modified my code to this which works:
But I am slightly confused here. What is the difference with UmbracoTemplatePage and UmbracoViewPage? One seems to be typed and one dynamic? If so I prefer typed. The designer obviously created my initial content as a UmbracoTemplatePage so I guess that is the new prefrerred way. Could I modify my code to fit in a UmbracoTemplatePage?
Hi Jakob,
I suggest you use UmbracoViewPage for the following 2 reasons
I tried to explain the difference between the two in this article for 24 days in Umbraco : https://24days.in/umbraco-cms/2015/strongly-typed-vs-dynamic-content-access/
Dave
is working on a reply...