Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
what is the best approach to getting images from a particular folder (within media) in umbraco?
i just want to get a set of images and loop thru them but cannot seem to get the right syntax to access the images....
Hi Mark,
Something like this:
@{ var myMediaFolder = Umbraco.Media(1234); foreach (var mediaItem in myMediaFolder.Children) { <li><a href="@mediaItem.Url">@mediaItem.Name</a></li> } }
If you have media picker to select the folder then change 2nd line to:
var myMediaFolder = Umbraco.Media(CurrentPage.myMediaPickerAlias);
I hope that makes sense?
Jeavon
yes thats great, thanks...
just a quick question, can i use the getCropUrl (imagecropper) extension with this format as i can when accessing a property value ?
Sure, if your Cropper has been put in place of the default Upload on the Image media type, then:
@{ var myMediaFolder = Umbraco.Media(1234); foreach (var mediaItem in myMediaFolder.Children) { <img href="@mediaItem.GetCropUrl("cropAlias")" /> } }
You might be interested in watch this video about using the Image Cropper
Hi Guys,
Here is a good method I use to firstly to get the containing media folder by name. You can then look through the children.
public static IPublishedContent GetFolderByName(string name, int? parentId = null) { var umbracoHelper = new UmbracoHelper(UmbracoContext.Current); if(parentId != null) { umbracoHelper.TypedMedia(parentId).Children("Folder").Where(x => x.Name == name).FirstOrDefault(); } return umbracoHelper.TypedMediaAtRoot().DescendantsOrSelf("Folder").Where(x => x.Name == name).FirstOrDefault(); }
Then call the method here
var mediaFolder = MediaManager.GetFolderByName("Some Folder Name"); foreach (var mediaItem in mediaFolder.Children) { //do whatever you want with the media here }
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
getting images from a media folder
what is the best approach to getting images from a particular folder (within media) in umbraco?
i just want to get a set of images and loop thru them but cannot seem to get the right syntax to access the images....
Hi Mark,
Something like this:
If you have media picker to select the folder then change 2nd line to:
I hope that makes sense?
Jeavon
yes thats great, thanks...
just a quick question, can i use the getCropUrl (imagecropper) extension with this format as i can when accessing a property value ?
Sure, if your Cropper has been put in place of the default Upload on the Image media type, then:
You might be interested in watch this video about using the Image Cropper
Jeavon
Hi Guys,
Here is a good method I use to firstly to get the containing media folder by name. You can then look through the children.
Then call the method here
is working on a reply...