Copied to clipboard

Flag this post as spam?

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


  • Sam 79 posts 426 karma points
    Dec 07, 2016 @ 19:40
    Sam
    0

    Trouble using Imagecropper with dynamic content to render css background image

    I am trying to render an image using image cropper and GetCropUrl for a css background image. I found the code below in the umbraco documentation, but I am having trouble making this dynamic.

    What is the proper way to pull the value based on the current page.

        @{
        var TopImage = Umbraco.TypedMedia(1234);
        if (TopImage != null)
        {
            <style>
            .InnerHero {
                background-image: url("@Url.GetCropUrl(TopImage, "TabletFull", false)");
            }
            </style>
        }
    
    }
    
  • Sam 79 posts 426 karma points
    Dec 08, 2016 @ 19:15
    Sam
    100

    I was able to get it working... most of my issue was syntax.

    I set a second variable to pull the value using Model.Content.GetPropertyValue

    var imgID = Model.Content.GetPropertyValue<int>("HeroImage");
    var TopImage = Umbraco.TypedMedia(imgID); 
    <style>
    .InnerHero {background-image: url("@Url.GetCropUrl(TopImage, "TabletFull", false)");}
    </style>
    
Please Sign in or register to post replies

Write your reply to:

Draft