Copied to clipboard

Flag this post as spam?

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


  • MBE 235 posts 816 karma points
    Mar 06, 2019 @ 15:23
    MBE
    0

    Getting first image of collection

    Hi guys,

    I just upgraded to 2.0 and I'm wondering how I can convert my old code. I'm struggeling getting the first image, here's my old code:

    /* First image */
                    var imageIds = CurrentPage.productImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    var images = Umbraco.Media(imageIds);
                    var firstImage = images.FirstOrDefault();
                    var firstImageUrl = firstImage.Url;
                    var firstImageCropUrl = firstImage.GetResponsiveImageUrl(433, 0);
    
    <img src="@firstImageCropUrl" alt="@firstImage.GetPropertyValue("altText")" title="@CurrentPage.GetPropertyValue("pageDescription")" />
    

    I can't seem to figure out how I could use the example from the documentation:

    <img src="@Url.GetCropUrl(featureImage, 270, 161, quality:30, furtherOptions:"&format=auto")" data-srcset="@Url.GetSrcSetUrls(featureImage, 270, 161)" data-src="@Url.GetCropUrl(featureImage, 270, 161)" sizes="auto" class="lazyload" />
    

    Any help is greatly appreciated.

    // Mike

  • Jeavon Leopold 3005 posts 13193 karma points MVP 7x admin c-trib
    Mar 24, 2019 @ 11:29
    Jeavon Leopold
    0

    Hi Mike,

    I'm sorry I missed the notification for your issue, did you manage to work it out?

    Jeavon

  • MBE 235 posts 816 karma points
    Mar 28, 2019 @ 13:08
    MBE
    0

    No worries Jeavon! I did in fact not solve it, I ended up dotting my way to the image path and displaying the full dimension. Bad practice, I know.. But width is set with CSS.

Please Sign in or register to post replies

Write your reply to:

Draft