Copied to clipboard

Flag this post as spam?

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


  • Keith Hubbard 174 posts 402 karma points
    Jan 10, 2018 @ 01:52
    Keith 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 3325 posts 11170 karma points MVP 5x 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 Hubbard 174 posts 402 karma points
    Jan 12, 2018 @ 20:20
    Keith 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 Hubbard 174 posts 402 karma points
    Jan 12, 2018 @ 20:43
    Keith Hubbard
    0

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

  • Keith Hubbard 174 posts 402 karma points
    Jan 12, 2018 @ 21:29
    Keith 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>
             }
    
  • 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