Copied to clipboard

Flag this post as spam?

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


  • pronto 61 posts 172 karma points
    May 14, 2014 @ 12:56
    pronto
    0

    Using the new Image Cropper in legacy Razor MacroScripts

    Hi everyone,

    I'm still getting to grips with Umbraco 7.1 and I still work a lot with the legacy Razor MacroScripts. My biggest problem is rendering image crops with the new image cropper inside a legacy Razor script, does anyone know if this is this actually possible? I have set up the new image cropper correctly (and managed to render crops within a Partial View macro), but using similar code in a legacy Razor script does not produce anything!

    My other attempted solution was to create a Partial View macro specifically for image crops, passing through an image id from a legacy Razor script, but I can't seem to render out a Partial View inside a legacy script at all! Is this also not possible?

    Kind Regards

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 14, 2014 @ 13:23
    Jeavon Leopold
    100

    Hi Pronto,

    While I would strongly urge you to refactor your MacroScripts to Partial View Macros, it should be possible to get crops using something like this:

    @using Newtonsoft.Json
    @using Umbraco.Web
    @using Umbraco.Web.Models
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
        var sidebarImage = CurrentModel.GetPropertyValue("sidebarImage");
        var imageCrops = JsonConvert.DeserializeObject<ImageCropDataSet>(sidebarImage);
        var myImageUrl = imageCrops.Src;     
    }
    <img src="@myImageUrl.GetCropUrl(imageCropperValue:sidebarImage, cropAlias:"myCropAlias", useCropDimensions:true)"/>
    

    Jeavon

  • pronto 61 posts 172 karma points
    May 14, 2014 @ 16:22
    pronto
    0

    Hi Jeavon,

    Thanks for the reply, I think I'm just going to take your advice and drop the legacy macros completely!

    Kind Regards

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 14, 2014 @ 18:53
    Jeavon Leopold
    0

    Is worth doing and there aren't that many changes really, you will see a performance improvement especially for collections like Descendants

Please Sign in or register to post replies

Write your reply to:

Draft