Copied to clipboard

Flag this post as spam?

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


  • MBE 244 posts 845 karma points
    Jul 31, 2019 @ 16:24
    MBE
    0

    Getting CropURL from specific node ID

    Hi guys,

    I'm using Umbraco 7.14.0 and attempting to get a crop url. It's getting pretty frustrating because I can find many solutions online but none of them work for me.

    • On each category page I have a property entitled dropdownImage enter image description here
    • I also have a crop alias of dropdown enter image description here
    • So on each menuItem I would like to see IF there is a image and if so - display the cropped image. It might just be my lack of experience but I can't believe how challenging it is to display a cropped image.

    (ignore this line, the editor goes crazy if I delete it)

    @foreach (IPublishedContent menuItem in menuItems.Where(x => x.GetPropertyValue<bool>("umbracoNaviHide") == false))
                {
                    var mediaItem = Umbraco.TypedContent(menuItem.Id).GetPropertyValue("dropdownImage");
                    if (mediaItem != null)
                    {
                        <img src="@menuItem.GetCropUrl("dropdownImage", "dropdown")" />
                    }
                }
    

    // Mike

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Jul 31, 2019 @ 20:25
    Marc Goodson
    1

    Hi Mike

    Try

    @foreach (IPublishedContent menuItem in menuItems.Where(x => x.IsVisible())
                {
                    var mediaItem = menuItem.HasValue("dropdownImage") ? menuItem.GetPropertyValue<IPublishedContent>("dropdownImage") : default(IPublishedContent);
                    if (mediaItem != null)
                    {
                        <img src="@(mediaItem.GetCropUrl("Dropdown"))" />
                    }
                }
    

    Now if the MediaPicker allows you to pick multiple images then it will return an enumerable of multiple images so to use the first you would have:

     var mediaItem = menuItem.HasValue("dropdownImage") ? menuItem.GetPropertyValue<IEnumerable<IPublishedContent>>("dropdownImage") .FirstOrDefault(): default(IPublishedContent);
    

    regards

    Marc

  • MBE 244 posts 845 karma points
    Aug 04, 2019 @ 08:11
    MBE
    0

    Hi Marc!

    Something happened because the bool return true now so I can actually get inside the if-statement.

    However the URL is still "unknown". I'm not sure if I'm running around in circles but the property alias "dropdownImage" is correct and the cropURL is correct "dropdown".

    I also made sure that all media files is "included in project" in my visual studio.

    You can see the backend values here: https://screenpresso.com/=KVGU

    // Mike

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Aug 04, 2019 @ 19:53
    Marc Goodson
    0

    Hi Mike nearly there...

    Unfortunately typo in my reply - updated!

    Should be

    mediaItem.GetCropUrl("banner")

    :-( #h5is

  • 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