Copied to clipboard

Flag this post as spam?

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


  • Chris Smith 39 posts 142 karma points
    Nov 07, 2014 @ 16:59
    Chris Smith
    0

    Built in Gallery Scripts to Render out Cropped Media

    Hi.

    I'm trying to setup an image gallery using the built in scripts but am having some issues getting the image urls populated in the image tag.  The default set up works fine but I've changed the Media section to upload images via a cropper so that the editors can do their own image manipulation.  

    Unfortunately this means that the default Gallery scripts returns full cropper data which isn't any good.  I've tried using the following code to address the crop I'm after but this just returns a blank src="".

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @*

        Macro to display a gallery from a media folder. Add the below parameter to the macro

        and use it to point the macro at a specific media folder to display it's content as

        a simple list.

     

        Macro Parameters To Create, for this macro to work:

        Alias:mediaId     Name:Media Folder ID    Type:Single Media Picker

    *@

    @if (Parameter.mediaId != null)

    {

         @* Get the media folder as a dynamic node *@

        var mediaFolder =  Library.MediaById(Parameter.mediaId);

            if (mediaFolder.Children.Any())

        {

            <ul class="thumbnails">

                @* for each item in children of the selected media folder *@

                @foreach (var mediaItem in mediaFolder.Children)

                {

    var cropUrl = mediaItem.GetCropUrl("umbracoFile", "thumb");

                    <li class="span2">

                        <a href="@cropUrl.umbracoFile" class="thumbnail">

                            <img src="@cropUrl" alt="@mediaItem.Name" />

                        </a>

                    </li>

                }

            </ul>

        }

    }

    Any pointers to where I'm going wrong would be great.

     

    Cheers

     

    Chris

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Nov 07, 2014 @ 18:02
    Dennis Aaen
    0

    Hi Chris and welcome to our.

    I think that you are missing one little thing. I assume that you link to the file works well, and therefore in the image tag where you call the url to the image you also need to add umbracoFile, to get the path to the image.

    So your image tag would look like this:

    <img src="@cropUrl.umbracoFile" alt="@mediaItem.Name" />

    And your hole script block would look like this:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @*

        Macro to display a gallery from a media folder. Add the below parameter to the macro

        and use it to point the macro at a specific media folder to display it's content as

        a simple list.

        Macro Parameters To Create, for this macro to work:

        Alias:mediaId     Name:Media Folder ID    Type:Single Media Picker

    *@

    @if (Parameter.mediaId != null){

         @* Get the media folder as a dynamic node *@

        var mediaFolder =  Library.MediaById(Parameter.mediaId);

            if (mediaFolder.Children.Any()){

            <ul class="thumbnails">

                @* for each item in children of the selected media folder *@

                @foreach (var mediaItem in mediaFolder.Children)

                {

                    var cropUrl = mediaItem.GetCropUrl("umbracoFile", "thumb");

                    <li class="span2">

                        <a href="@cropUrl.umbracoFile" class="thumbnail">

                            <img src="@cropUrl.umbracoFile" alt="@mediaItem.Name" />

                        </a>

                    </li>

                }

            </ul>

        }

    }

    Try to see the uHangout EP030 - Jeavon Leopold episode of uHangout where Jeavon talks about the image cropper and how to configure it. http://uhangout.co.uk/video/bQsvGmnYaUU

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft