Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jakob Lithner 61 posts 264 karma points
    May 08, 2018 @ 06:50
    Jakob Lithner
    0

    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?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 08, 2018 @ 07:00
  • Jakob Lithner 61 posts 264 karma points
    May 08, 2018 @ 21:54
    Jakob Lithner
    0

    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.

  • Jakob Lithner 61 posts 264 karma points
    May 09, 2018 @ 18:45
    Jakob Lithner
    0

    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:

    @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?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    May 10, 2018 @ 09:40
    Dave Woestenborghs
    0

    Hi Jakob,

    I suggest you use UmbracoViewPage for the following 2 reasons

    • UmbracoTemplatePage inherits from UmbracoViewPage and adds support for dynamics
    • If am correct UmbracoTemplatePage will be removed in v8 along with support for dynamics.

    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

Please Sign in or register to post replies

Write your reply to:

Draft