I have media items including folders. I am able to list the contents of the media root using this code:
@foreach (var child in Umbraco.TypedMediaAtRoot()) {
<h5>@child.Url | @child.Name</h5>}
I can't figure out how to start with a folder under the root. I don't get any IntelliSense in VS2015, and I am having problems discovering the right solution.
You have to decide how you want to select that folder, the easiest way is to use its id, then you can use @Umbraco.TypedMedia(1234). Other methods could be to create a specific folder media type or to select by name
@{
var myFolder = Umbraco.TypedMediaAtRoot().FirstOrDefault(f => f.Name == "Documents");
foreach (var child in myFolder) {
<h5>@child.Url | @child.Name</h5>
}
}
generates this error:
foreach statement cannot operate on variables of type 'Umbraco.Core.Models.IPublishedContent' because 'Umbraco.Core.Models.IPublishedContent' does not contain a public definition for 'GetEnumerator'
Unable to list media items from razor template
I have media items including folders. I am able to list the contents of the media root using this code:
I can't figure out how to start with a folder under the root. I don't get any IntelliSense in VS2015, and I am having problems discovering the right solution.
You have to decide how you want to select that folder, the easiest way is to use its id, then you can use
@Umbraco.TypedMedia(1234)
. Other methods could be to create a specific folder media type or to select by nameI would like to select it by name
Ok, then assuming the folder is in the root I would use something like this:
now this code:
generates this error:
I think myFolder should have a Children property so it would be
see this very similar thread for ideas on how to achieve what you're after
https://our.umbraco.org/forum/developers/razor/63629-Iterate-through-Media-Folder
Absolutely correct!
Thank you all so much. It is working and I finally understand how to use it.
is working on a reply...