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 581 posts 1385 karma points
    Nov 13, 2011 @ 12:10
    Sebastian Dammark
    0

    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>
    
    <xsl:template match="Folder">
        <ul>
            <xsl:apply-templates select="Image" />
        </ul>
    </xsl:template>
    
    <xsl:template match="Image">
        <li>
            <a href="{umbracoFile}">
                <img src="{cropset/crops/crop[@name='photosMedium']/@url}" alt="{@nodeName}" />
            </a>
        </li>
    </xsl:template>
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Nov 13, 2011 @ 14:54
    Jeroen Breuer
    1

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

    Jeroen

  • Sebastiaan Janssen 5045 posts 15477 karma points MVP admin hq
    Nov 17, 2011 @ 19:53
    Sebastiaan Janssen
    0

    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:

    <h2>@Model.Name</h2>
    
    <h3>Digibiz Advanced Media Picker</h3>
    @{
        if (Model.HasValue("Media")) {
            dynamic mediaItems = Model.Media.mediaItem;
            if (mediaItems.Count() != 0)
            {
                <ul>
                @foreach (var item in mediaItems)
                {
                    var image = item.Image;
                    <li>
                        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"/>
                        }
                    </li>
                }
                </ul>
            }
        }
    }
  • Jon Free 14 posts 34 karma points
    Feb 29, 2012 @ 17:01
    Jon Free
    0

    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:

Draft