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 166 posts 372 karma points
    1 week ago
    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 2409 posts 6836 karma points mvp c-trib
    6 days ago
    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 166 posts 372 karma points
    5 days ago
    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 1171 posts 1284 karma points
    5 days ago
    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 166 posts 372 karma points
    5 days ago
    Keith Hubbard
    0

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

  • Keith Hubbard 166 posts 372 karma points
    5 days ago
    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>
             }
    
Please Sign in or register to post replies

Write your reply to:

Draft