Copied to clipboard

Flag this post as spam?

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

  • organic 108 posts 157 karma points
    Jun 22, 2012 @ 00:09

    Get Crops with Razor syntax

    Has anyone gotten the crop urls with razor? The 'Crops' property is empty.

    I'm accessing my other properties simply like @sliderItem.Title, but @sliderItem.Crops is empty, eventhough umbraco.config shows a 'crops' node at the same level as 'Title'

    I'm guessing I'll have to do the string manipulation on the original upload url

  • Chizzl 36 posts 107 karma points
    Jun 26, 2012 @ 09:21

    Maybe this can help you;

    <img src="@yourCurrentNode.aliasOfYourCropper.Find("@name", "Name of the crop you want").url" />
    Maybe this post can be helpfull too as a sample to start from;
  • Damiaan 442 posts 1301 karma points MVP 6x c-trib
    Sep 05, 2012 @ 10:47


    Your link ends up on a 500 server errror:

    Error running Reader: 
    SQL Statement:
    select id, domainName from umbracoDomains

    System.Data.SqlServerCe.SqlCeException: The database file may be corrupted.
  • Chizzl 36 posts 107 karma points
    Sep 06, 2012 @ 22:36

    Sadly enough I have no control over that website.  I was only pointing to a blog article...

  • organic 108 posts 157 karma points
    Mar 25, 2013 @ 20:01

    @Chizzl's solution works well:

    @sliderItem.crops.Find("@name", "MainSlider").url


    And now in MVC, it just needs this small edit to continue working:

    @sliderItem.AsDynamic().crops.Find("@name", "MainSlider").url;

  • Karen 8 posts 98 karma points
    May 07, 2014 @ 19:31

    <img src="@Model.Media.cropImage.crop.crops.Find("@name","mainPageImage").url" alt="what the" />

    Hello sorry going round in circles, the above does not throw an error it displays the alt tag.

    Don't really get the data type image cropper crops. I was expecting the image cropper to enable a new sized image to be created that could then be resaved with a different name in Media.

    But as I understand it now the image cropper (with no ux clue that it has done so) saves the cropped information to an xml file called crop with attributes that you access using the word crops and the syntax .Find.

    To use this new cropped image you then have to add some code to the template where you want the image to be placed referencing this crop file.

    And now to my question, (if you are still with me!) I have been trying to use and understand what appears to be a very straight forward razor template from Chizzl's solution

    <img src="@yourCurrentNode.aliasOfYourCropper.Find("@name", "Name of the crop you want").url" />
    but my code is not working. Please can you tell me why?
    I took @yourCurrentNode to mean the current page and so I used Model, I want too access Media so .Media and then I got lost to which is the alias of my cropper. Within settings under Media Types and then Image I created a property under a Tab I named CropImageSize with an alias of cropImage and with the Type of, Image Cropper, so I used that.
    <img src="@Model.Media.cropImage.Find("@name","mainPageImage").url" alt="what the" />
    I have also tried
    <img src="@Model.Media.cropImage.crop.crops.Find("@name","mainPageImage").url" alt="what the" />
    (mainPageImage is one of the crop sizes I set up in the Image Cropper). I take it @name is the name of the image, which the code will get from the image file when its added to the page by the editor using the media picker.
    Sorry for the long post but I wanted to eplain my understanding so that it could be corrected if I have misunderstood. I have watched the umbraco video 'image cropper dataType' by Tim but he is using xslt.
    Thanks for any clue to why the image url of my cropped images is not being found. Karen
Please Sign in or register to post replies

Write your reply to: