I have a folder on media section called Slider. Under that folder there are many images.
I also added my document type a media picker called pictures. After pointing slider folder,
How can I loop through all the images by getting the url under Slider folder on media section using razor?
You can loop through all the images by using this piece of code.
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{
if (CurrentPage.HasValue("pictures")){
var dynamicMediaFolder = Umbraco.Media(CurrentPage.pictures);
<ul>
@foreach (var picture in dynamicMediaFolder.Children)
{
<li>
<a href="@picture.Url">
<img src="@picture.umbracoFile" alt="@picture.Name" />
</a>
</li>
}
</ul>
}
}
Then you will print the image in a unordered list and get the url to the images. In my example I am using partial view macro files, but you can also use partial views
Loop through all images in a folder?
Hi All,
I have a folder on media section called Slider. Under that folder there are many images. I also added my document type a media picker called pictures. After pointing slider folder,
How can I loop through all the images by getting the url under Slider folder on media section using razor?
Hi ds,
You can loop through all the images by using this piece of code.
Then you will print the image in a unordered list and get the url to the images. In my example I am using partial view macro files, but you can also use partial views
You are saying that you are using the content picker, then I take the seleted id of the folder and loop through the children (the images). You can find the documentation for the content picker here: https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker
I have used the dycnamic Razor, but you can also use the strongly typed Razor.
Hope this helps,
/Dennis
Hi Dennis,
It works like a charm. Thank you very much for the help. I only changed first line
inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Hi ds,
Sounds nice that it works like intended.
Yes then you are using Partial Views instead of Partial Views Macros.
/Dennnis
is working on a reply...