Copied to clipboard

Flag this post as spam?

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


  • Charles Cherry 2 posts 72 karma points
    Nov 28, 2017 @ 22:45
    Charles Cherry
    0

    Need help understanding Nested Content

    I am brand new to Umbraco and trying to wrap my head around what's happening.

    I am trying to implement a bootstrap carousel. I want the end users to be able to choose the banner images and banner text, so I created a new Doc Type called "BannerSlide" to represent a single slide in the carousel. It has two properties, banner image and alt text.

    I created a new data type using the Nested Content. Then on my home page doc type I added a tab and used the new data type for my editor. So far so good.

    In the template for the home page, I added this code:

        <!-- Wrapper for slides -->
        <div class="carousel-inner">
            @{
                var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>("homePageCarouselBanner");
                foreach(var item in items)
                {
                    @Umbraco.Field(item)
                }                    
            }
    
        </div>
    

    Then I went the content for Home Page, and the carousel editor showed up, allowed me to choose the images for multiple slides. So far so good.

    I hit save and publish, but when I go to the site, I get a yellow screen of death and the error message:

    'Umbraco.Web.Models.RenderModel

    What did I do wrong?

  • Steve Morgan 1278 posts 4216 karma points c-trib
    Dec 01, 2017 @ 14:51
    Steve Morgan
    0

    Hi

    I think you need something like

            @{
            var items = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("homePageCarouselBanner");
            foreach (var item in items)
            {
                var slideImage = item.GetPropertyValue<IPublishedContent>("bannerImage");
                // check an image has been picked
                if(slideImage != null)
                {
                    var slideTitle = item.GetPropertyValue<string>("altText");
                    <img src="@slideImage.Url" title="@slideTitle"/>
                }
    
            }
        }
    

    That's untested so it might need tweaking.

    HTH Steve

  • Charles Cherry 2 posts 72 karma points
    Dec 01, 2017 @ 17:29
    Charles Cherry
    0

    Thanks, that got me going in the right direction!

  • 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.

Please Sign in or register to post replies