Copied to clipboard

Flag this post as spam?

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

  • Sebastian Dammark 523 posts 1187 karma points
    Nov 13, 2011 @ 12:10
    Sebastian Dammark

    Get images with a specific cropping ?

    Well ... how do I do that ?

    It's fairly easy in XSLT but I just can't seem to figure it out in Razor.

    Here is my XSLT example:

    <xsl:template match="Photos">
        <xsl:variable name="images" select="umb:GetMedia(images, 1)" />
        <xsl:apply-templates select="$images[Image[cropset/crops/crop[@name='photosMedium']]]" /></ul>
    <xsl:template match="Folder">
            <xsl:apply-templates select="Image" />
    <xsl:template match="Image">
            <a href="{umbracoFile}">
                <img src="{cropset/crops/crop[@name='photosMedium']/@url}" alt="{@nodeName}" />
  • Jeroen Breuer 4861 posts 12129 karma points MVP 3x admin c-trib
    Nov 13, 2011 @ 14:54
    Jeroen Breuer

    Did you have a look at the Cultiv Razor Examples project? It also has some cropping examples.


  • Sebastiaan Janssen 4861 posts 14484 karma points MVP admin hq
    Nov 17, 2011 @ 19:53
    Sebastiaan Janssen

    Here's the Razor example (note the @crops.Find in there), this assumes that your DAMP picker has an alias of "media" and that you store the media XML in your umbraco.config:

    <h3>Digibiz Advanced Media Picker</h3>
        if (Model.HasValue("Media")) {
            dynamic mediaItems = Model.Media.mediaItem;
            if (mediaItems.Count() != 0)
                @foreach (var item in mediaItems)
                    var image = item.Image;
                        Original image: <a href="@image.umbracoFile">@image.nodeName</a> (@image.umbracoBytes bytes)<br />
                            If the type of the mediacropper is not XML (but a string) then there 
                            are no crops defined, so I should not try to find the crops.
                        @{ var crops = image.mediaCropper; }
                        @if (crops.GetType().ToString() != "System.String")
                            <text>Crops:</text><br />
                            <img src="@crops.Find("@name", "Thumbnail").url" alt="@image.nodeName"/><br />
                            <img src="@crops.Find("@name", "Header").url" alt="@image.nodeName"/>
  • Jon Free 14 posts 34 karma points
    Feb 29, 2012 @ 17:01
    Jon Free

    Don't you need to defend against the crops not existing?

    <imgsrc="@crops.Find("@name", "Thumbnail").url"alt="@image.nodeName"/><br/>

    What if Find() returns nothing?

Please Sign in or register to post replies

Write your reply to: