Copied to clipboard

Flag this post as spam?

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


  • Keith R Hubbard 175 posts 403 karma points
    Jan 10, 2018 @ 01:52
    Keith R Hubbard
    0

    Getting image to work for IPublishedContent with nested Content

    I have a Testimonial us Nested Content. for some reason i cannot get the image.

    var items = Model.GetPropertyValue<IEnumerable<IPublishedContent>>
    ("testimonial");
    
    foreach (var item in items)
    {
    
        /*var typedMediaPickerSingle = Model.GetPropertyValue.<IPublishedContent>("image");*/
    
            var image = item.GetPropertyValue<IPublishedContent>("image");
            if (item.HasValue("image"))
            {
                <h2>@item.GetPropertyValue("testimonialName")</h2>
                <img src="@image.Url" style="width:200px" alt="@item.Name" />
                <h3>@item.GetPropertyValue("location")</h3>
                <h4>@item.GetPropertyValue("quote")</h4>
            }
    
    
    }
    

    I get all properties but the image. I have tried all documentation for media picker with errors .

    testimonial image

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Jan 12, 2018 @ 10:16
    Dave Woestenborghs
    1

    Hi Keith,

    What does the url point to ? Do you get a url ? Because it seems to find a image.

    Dave

  • Keith R Hubbard 175 posts 403 karma points
    Jan 12, 2018 @ 20:20
    Keith R Hubbard
    0

    Dave

    I followed Jeavon's direction some time ago and set the image media type to umbracoFile Alias. I am thinking this may have something to do with it. I am using the Media Picker with Multiple images disabled.

    Media Picker with Multiple diabled

    /*var typedMediaPickerSingle = Model.GetPropertyValue<IPublishedContent>("image");*/
        /*var image = Umbraco.TypedMedia(@item.GetPropertyValue("image"));*/
        /*var image = item.GetPropertyValue<IPublishedContent>("image");*/
        var imageUrl = item.GetPropertyValue<IEnumerable<IPublishedContent>>("testimonialImage");
        if (item.HasValue("testimonialImage"))
        {
            <div class="col-md-4 col-sm-6 item">
                <h2>@item.GetPropertyValue("testimonialName")</h2>
                <img src="@imageUrl" height="200" width="200" alt="@item.Name" />
                <h3>@item.GetPropertyValue("location")</h3>
                <h4>@item.GetPropertyValue("quote")</h4>
            </div>
        }
    

    Here is the latest code. I know that it is reading the items because i get the alt of the image But i get an broken image.

  • bob baty-barr 1180 posts 1294 karma points MVP
    Jan 12, 2018 @ 20:36
    bob baty-barr
    1

    looks like a pretty recent install... is it mediapicker2? https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Media-Picker2

    is any of that helpful?

  • Keith R Hubbard 175 posts 403 karma points
    Jan 12, 2018 @ 20:43
    Keith R Hubbard
    0

    Bob I tried that but, thanks for trying to help.

  • Keith R Hubbard 175 posts 403 karma points
    Jan 12, 2018 @ 21:29
    Keith R Hubbard
    101

    I was able to get it working!!!!

    foreach (var item in items)
            {
    
                var imageUrl = item.GetPropertyValue<IPublishedContent>("testimonialImage");
                if (item != null)
                {
                    <div class="col-md-4 col-sm-6 item">
                          <h2>@item.GetPropertyValue("testimonialName")</h2>
                          <img src="@imageUrl.Url" height="200" width="200" 
                          alt="@item.Name" />
                          <h3>@item.GetPropertyValue("location")</h3>
                          <h4>@item.GetPropertyValue("quote")</h4>
                    </div>
             }
    
Please Sign in or register to post replies

Write your reply to:

Draft