Copied to clipboard

Flag this post as spam?

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


  • Harry Spyrou 212 posts 604 karma points
    Nov 16, 2016 @ 21:23
    Harry Spyrou
    0

    Umbraco v6.1.6 and Cropped Url Problem

    So my company wants me to make a small blog on the main website and everything goes well, only...

    I was hitting my head against the wall today as I was used to umbraco 7. Now, apparently Umbraco 6 doesn't have the very handy @Url.GetCropUrl Which brings me to my next problem. Tried to find the documentation for that version and nothing on the web. Anyone has any clues on where I can find the previous documentation about the Image Cropper in v6.1 and how to grab the cropped urls with Razor?

    Thank you in advance.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 17, 2016 @ 07:42
    Dennis Aaen
    1

    Hi Harry,

    Perhaps this old documentation can help you in the right direction try to look at https://github.com/umbraco/UmbracoDocs/blob/v7-documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Image-Cropper.md

    If you not are using Dynamic Razor in your 6.1.6 then you need to make some changes to the Razor code that you are seen in the example.

    Hope this can help you in the right direction.

    /Dennis

  • Harry Spyrou 212 posts 604 karma points
    Nov 17, 2016 @ 12:15
    Harry Spyrou
    0

    Hello Dennis,

    Unfortunately it didn't help. I did what the documentation told me using Razor and unfortunately MediaById returns error:

    RenderModel does not contain a definition of "MediaById' and no extension method 'MediaById' accepting a first argument of Type "RenderModel" could be found (are you missing an assembly reference?)

    my @using are:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Web.Mvc
    @using System.Web.Mvc.Html
    

    here's where it gets really weird. When I saw the documentation won't help me (as per usual) I tried stuff on my own. I have a Blog Document Type and then a descendant(3rd level I think) which is named BlogPost.

    I'm using this code in BlogPost:

    @if (Model.Content.HasValue("blogBanner"))
                                    {
                                        var bannerImage = Umbraco.Media(Model.Content.GetPropertyValue<string>("blogBanner"));
                                        var croppedPhoto = bannerImage.thumbnails.crops.Find("@name", "BlogBanner").url;
    
    
    
                                        <img src="@croppedPhoto" alt="@croppedPhoto" />
                                    }
    

    To get the crop ("BlogBanner") from the Image Cropper "thumbnails" and it works. I go back to the Blog, grand-grandparent and I use this code:

     @foreach (var blogPost in Model.Content.Descendants("BlogPost"))
                    {
    
                        <div class="col-md-4 text-center">
                            <div class="post-preview-image">
                                <a href="@blogPost.Url">
                                    @if (blogPost.HasValue("blogBanner"))
                                    {
                                        var bannerImage = Umbraco.Media(blogPost.GetPropertyValue<string>("blogBanner"));
                                        var croppedPhoto = bannerImage.thumbnails.crops.Find("@name", "previewImage").url;
    
    
    
                                        <img src="@croppedPhoto" alt="@croppedPhoto" />
                                    }
                                </a>
    
                                <a href="@blogPost.Url">
                                    <p>@blogPost.Name</p>
                                </a>
                                <h6>@(blogPost.GetPropertyValue<string>("date"))</h6>
                            </div>
    
    
    
                        </div>
                    }
    

    and it DOESN'T WORK...... Throws an exception:

    'Umbraco.Core.Dynamics.DynamicXml' does not contain a definition for 'url'

    On the @croppedPhoto variable. I have NO IDEA how to make it work. I've tried everything. It's a media picker by the way if that helps. I tried Upload image instead of Media Picker, but it's the same exact result.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 17, 2016 @ 20:15
    Dennis Aaen
    0

    Hi Harry,

    Perhaps you could consider using this package https://our.umbraco.org/projects/website-utilities/eksponent-cropup

    Try to see JeavonĀ“s comment in this thread:

    https://our.umbraco.org/forum/developers/razor/53413-Getting-Image-Crop-from-media-picker-file

    Hope this helps,

    /Dennis

  • 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