Copied to clipboard

Flag this post as spam?

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


  • Tobi Fondse 2 posts 82 karma points
    May 04, 2019 @ 00:08
    Tobi Fondse
    0

    GetCropUrl in a selection in a macro

    In Umbraco 8.02 I have some trouble getting an image with GetCropUrl. I have a macro from a Umbraco template and the content type has a crop image. Listing the nodes is no problem, just the right crop url. Below is the code I use with some comments. I tried to convert the field value (to what?) and call Url.GetCropUrl. All lead to an empty value or an error message. Someone is able to help me with this?

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using Umbraco.Web
    
    @* Get the starting page *@
    var startNode = Umbraco.Content(startNodeId);
    var selection = startNode.Children.Where(x => x.IsVisible()).ToArray();
    
    if (selection.Length > 0)
    {
    
    <div class="row">
        @foreach (var item in selection)
        {
        var image = item.Value<string>("headerImage"); // string returns json, without type it returns Umbraco.Core.PropertyEditors.ValueConverters.ImageCropperValue
            <div class="col-md-4">
                @image -> Image url
                @image.GetCropUrl("overview") -> error
                @Url.GetCropUrl("headerImage", "overview") -> error
            <p><a href="@item.Url">@item.Name</a></p>
            </div>
        }
    </div>
    }
    
  • Søren Kottal 712 posts 4570 karma points MVP 6x c-trib
    May 04, 2019 @ 14:55
    Søren Kottal
    100

    Hi Tobi

    I think you should get the image value as ImageCropperValue. Then you should be able to use the GetCropUrl overload.

  • Tobi Fondse 2 posts 82 karma points
    May 04, 2019 @ 21:45
    Tobi Fondse
    0

    Hi Søren

    Thanks, this did the trick. Didn't think about typing it explicitly.

Please Sign in or register to post replies

Write your reply to:

Draft