Copied to clipboard

Flag this post as spam?

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


  • dan 54 posts 133 karma points
    Aug 03, 2015 @ 02:45
    dan
    0

    Get media files of a specific datatype

    I'm creating a really basic image slider which loads in images uploaded as a datatype; "sillyimage". I want to be able to grab all images of that type with razor.

    Since there is no parameter tied to a page I'm not sure how to go about it.

    How can one get an object containing a list of all the media files of a specific type?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Aug 03, 2015 @ 11:36
    Dennis Aaen
    100

    Hi Dan,

    Is it right if I assume that you are picking the images, by using the media picker, and then want to loop though the images in the folder.

    If so then is code snippet should be a good starting point.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @if(CurrentPage.HasValue("mediaPickerAlias"))
    {
        var media = Umbraco.Media(CurrentPage.mediaPickerAlias);
        var selection = media.Children("Sillyimage");
    
        if (selection.Any())
        {
            <ul>
                @foreach (var item in selection)
                {
                    <li>
                        <img src="@item.umbracoFile" alt="@item.Name" />
                    </li>
                }
            </ul>
        }
    }
    

    Remember to change the media picker alias so it match your case.

    Hope this helps,

    /Dennis

  • dan 54 posts 133 karma points
    Aug 06, 2015 @ 19:23
    dan
    0

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft