Copied to clipboard

Flag this post as spam?

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


  • Martin Rud 261 posts 1022 karma points c-trib
    May 07, 2021 @ 06:12
    Martin Rud
    0

    "'IPublishedContent' does not contain a definition for 'GetCropUrl'" in my method

    Hi,

    I am creating a method that returns html for a picture element, but gets the below error.

    My code is:

    public static string PictureHtml(string[] srcsets, IPublishedContent image, string classAttr)
    {
        string output = "";
        int i = 1;
    
        foreach (var srcset in srcsets)
        {
            string[] srcsetAttributes = srcset.Split('|');
            if(i != srcsets.Count())
            {
                output += "<srcset src=\"" + image.GetCropUrl(200, 200) + "\" />";
            } else {
                output += "<img src=\"" + image.GetCropUrl(200, 200) + "\" alt=\"" + image.Name + "\" />";
            }
            i++;
        }
    
        return "<picture class=\"" + classAttr + "\">" + output + "</picture>";
    }
    

    Code isn“t finished yet and therefore GetCropUrl parameters are hardcoded to 200.

  • Nik 1625 posts 7295 karma points MVP 8x c-trib
    May 07, 2021 @ 08:40
    Nik
    102

    Hi Martin,

    I think you need to include the Umbraco.Web namespace as GetCropUrl is an extension method.

    Thanks

    Nik

  • Martin Rud 261 posts 1022 karma points c-trib
    May 07, 2021 @ 08:42
    Martin Rud
    0

    That works! Thanks!

  • 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