Copied to clipboard

Flag this post as spam?

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


  • David Gregory 82 posts 208 karma points
    Sep 14, 2015 @ 10:31
    David Gregory
    0

    Dispaly image from media folder

    Hello community

    Newbie question here:

    I have created a folder in the media section called 'banner'. Now in my template I simply want to display the first image in that folder.

    The idea will be that a user can change the banner image on the website just by changing the image in the folder. I could do this at the document type level but the banner won't change that often so I don't want to bother the users with an extra tab and content area to upload an image if it's not a regular changing area.

    using Umbraco 7.2.8

    Thanks David

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 14, 2015 @ 10:36
    Dennis Aaen
    0

    Hi David,

    I would consider using the media picker, so your user can choose the picture they want for the banner, and they choose it from the media library, instead of using the upload data type.

    To get data from the media picker in Razor take a look at this documentation.

    https://our.umbraco.org/documentation/getting-started/backoffice/property-editors/built-in-property-editors/media-picker

    Hope this helps,

    /Dennis

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 14, 2015 @ 10:50
    Dennis Aaen
    100

    Hi David,

    If you just want your user to update the folder ID then you can use the following Razor script, but remember to update the ID of the folder in your media library. In my case it´s 1080.

    @{
        var media = Umbraco.Media(1080);
        var selection = media.Children("Image");
    
        if (selection.Any())
        {
            <ul>
                @foreach (var item in selection.Take(1))
                {
                    <li>
                        <img src="@item.umbracoFile" alt="@item.Name" />
                    </li>
                }
            </ul>
        }
    }
    

    Hope this helps,

    /Dennis

  • David Gregory 82 posts 208 karma points
    Sep 14, 2015 @ 12:03
    David Gregory
    0

    Great, couple of good options there, your second one is exactly what I need actually.

    thanks

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Sep 14, 2015 @ 12:06
    Dennis Aaen
    0

    Hi David,

    You are welcome. Does it work like you wanted to or?

    /Dennis

  • David Gregory 82 posts 208 karma points
    Sep 14, 2015 @ 14:11
    David Gregory
    0

    perfect.

Please Sign in or register to post replies

Write your reply to:

Draft