Copied to clipboard

Flag this post as spam?

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


  • josee 2 posts 82 karma points
    Aug 30, 2018 @ 10:27
    josee
    0

    Can't get (legacy) media picker to be displayed with nested content

    Hi all,

    I'm working on a website with Umbraco 7.5.4., which I didn't build but need to make some changes. I have nested content and I'm trying to display this. I get the title displayed correctly, but not my images.

    The code I'm using is as followed:

    @foreach (var item in selection) {
        <p>@item.Name</p>
        var subItems = item.GetPropertyValue<IEnumerable<IPublishedContent>>("hoofdstuk");
    
        if (subItems != null) {
            foreach (var subItem in subItems) {
                if (subItem != null) {
                    <p><strong>@Umbraco.Field(subItem, "nummer")</strong> @Umbraco.Field(subItem, "titel")</p>
                    var file = Umbraco.Media(subItem.bestand);  
    
                    if (file != null) {
                        <a href="@file.Url">Link</a>
                    }
                }
            }
        }
    }
    

    I got the following error: 'Umbraco.Web.Models.PublishedContentBase' does not contain a definition for 'bestand' For the content in my <p> tag I solved it by using @Umbraco.Field but how to solve this for the Media Picker?

    I noticed the Media Picker used is the Legacy Media Picker with the alias Umbraco.MediaPicker.

    I don't have the possibility to upgrade this version of Umbraco.

    I hope someone can help me out.

  • Bas Schouten 135 posts 233 karma points
    Aug 30, 2018 @ 14:34
    Bas Schouten
    100

    I was able to fix it with:

    @foreach (var item in selection) {
        <p>@item.Name</p>
        var subItems = item.GetPropertyValue<IEnumerable<IPublishedContent>>("hoofdstuk");
        if (subItems != null) {
            foreach (var subItem in subItems) {
                if (subItem != null) {
                    var node = @Umbraco.Field(subItem, "bestand");
                    var image = Umbraco.Media(@node.ToString());                    
                    <p>
                    @if (@image.url.Length > 0){
                        <a href="@image.url"><strong>@Umbraco.Field(subItem, "nummer")</strong> @Umbraco.Field(subItem, "titel")</a>
                    }
                    else{
                        <strong>@Umbraco.Field(subItem, "nummer")</strong> @Umbraco.Field(subItem, "titel")
                    }
                    </p>
                }
            }
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft