Copied to clipboard

Flag this post as spam?

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


  • Dominic 8 posts 90 karma points
    Mar 01, 2019 @ 13:56
    Dominic
    0

    Get URL of media picker property of all children in a foreach loop

    Hi,

    I am trying to display images from child nodes in the parent page by getting the media picker value (id of media image) within a foreach loop for each child, but it just returns the mediatype - Umbraco.Web.PublishedModels.Image*

    @foreach (var group in Model.Children.InGroupsOf(4))
    {
        <div class="row">
            @foreach (var item in group)
            {
                <img src="@Umbraco.Media(item.Value("summaryImage")).GetCropUrl("SummaryImageCrop")" />
    
            }
        </div>
    }
    

    The problem seems to be that @item.Value(propertyAlias) does not return the ID.

    Can anyone see what I am doing wrong please?

  • Sören Deger 733 posts 2844 karma points c-trib
    Mar 01, 2019 @ 15:05
    Sören Deger
    0

    Hi Dominic,

    which version of Umbraco do you use?

    Maybe item.Value("summaryImage") contains already the converted IPublishedContent Object instead the Id. Can you try, if

    @item.Value("summaryImage").GetCropUrl("SummaryImageCrop")
    

    without @Umbraco.Media works for you?

    Best, Sören

  • Dominic 8 posts 90 karma points
    Mar 01, 2019 @ 15:08
    Dominic
    0

    Thanks - I am using V8.

    But GetCropUrl method is not available

    Trying @item.GetCropUrl("summaryImage","SummaryImageCrop") returns Umbraco.Web.PublishedModels.Imagemode=pad&rnd=131959248365800000

  • Dominic 8 posts 90 karma points
    Mar 01, 2019 @ 15:41
    Dominic
    2

    This worked..

                                    @if (item.HasValue("summaryImage"))
                                    {
                                        <a href="@item.Url">
                                            @{
                                                var image = item.Value<IPublishedContent>("summaryImage");
                                            }
                                            <img src="@image.GetCropUrl("summaryImageCrop")" />
                                        </a>
                                    }
    
  • 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