Copied to clipboard

Flag this post as spam?

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


  • MB 273 posts 936 karma points
    Mar 06, 2019 @ 15:23
    MB
    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 3074 posts 13632 karma points MVP 11x 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

  • MB 273 posts 936 karma points
    Mar 28, 2019 @ 13:08
    MB
    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.

  • 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