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.
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.
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>
}
}
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
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
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.
Hope this helps,
/Dennis
Great, couple of good options there, your second one is exactly what I need actually.
thanks
Hi David,
You are welcome. Does it work like you wanted to or?
/Dennis
perfect.
is working on a reply...