Copied to clipboard

Flag this post as spam?

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


  • lori ryan 239 posts 573 karma points
    Jun 06, 2018 @ 12:00
    lori ryan
    0

    Is it possible to reference an image that's embedded in a grid?

    Hi I have a news article. Ive used grid to build up the article template. On row two I have an image, there will always be an image there. Is it possible to reference an image that's embedded in a grid from a macro? Any helpers or points would be fantastic.

  • Søren Gregersen 441 posts 1884 karma points MVP 2x c-trib
    Jun 06, 2018 @ 12:27
    Søren Gregersen
    0

    yes and no :)

    Do you want to reference it in a controller, razor, clientside etc?

    It's "just" json, so you can parse it , and check if the second row contains an image.

    If you are on the server (a controller or razor) you are able to use the Skybrud.Umbraco.GridData package - read more here: https://skrift.io/articles/archive/strongly-typed-models-in-the-umbraco-grid/

    Inside the grid partial, you can also check if the row number is 2, and if the control being rendered is using the editor named "image"

  • lori ryan 239 posts 573 karma points
    Jun 06, 2018 @ 13:11
    lori ryan
    1

    Hey So am sure there are 100 ways to do this better

            var myGrid =   @item.GetPropertyValue("articleGrid").ToString();
            var myIndex = myGrid.ToString().IndexOf("udi");
            myIndex = myIndex + 6; 
    
            var myImagePartOne = myGrid.Substring(@myIndex,500);
             var myEndIndex = myImagePartOne.ToString().IndexOf(",");
            var myImageUDI = myImagePartOne.Substring(0,myEndIndex).Replace('"', ' ').Trim();
    
            var udi = Udi.Parse(myImageUDI);
            var media = Umbraco.TypedMedia(udi);
            var  imageToShow = Url.GetCropUrl(media, 120, 120,quality:90, furtherOptions:"&format=jpg");
    

    But I got my image and it uses the image cropper.

Please Sign in or register to post replies

Write your reply to:

Draft