Hi all, I am trying to render one image from each media folder (when the parent folder is selected) the structure is like this
Gallery Folder
sub folder
img
sub folder
img
img
I've made a little progress with the below, but it only renders images when a sub folder is selected, does anyone know how I could tweak this to display one image from each folder when the parent is selected please?
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.cms.businesslogic.media;
<ul class="image-gallery">
@{
var mediaPicker = @Model.imageGallery;
if (!String.IsNullOrEmpty(mediaPicker)) {
int folderId = Convert.ToInt32(mediaPicker);
var mediaFolder = new Media(folderId);
if (mediaFolder.ChildCount > 0) {
IEnumerable<Media> Folder = mediaFolder.GetChildMedia().Where(x => x.ContentType.Alias == "Image");
foreach (var img in Folder) {
<li>
<a href="#">
<img src="/[email protected]("umbracoFile").Value&width=200&height=140" alt="" />
</a>
</li>
}
}
}
}
</ul>
To check a couple of things, is "Gallery Folder" a folder in the media section rather than content and you have a property on your page that is rendering on the front end that has a media picker on it, you pick a "sub folder" with that picker but you want to render only the first image in that "sub folder"?
Yep 'gallery folder' is a folder in the media section
Yea on the page there is a media picker where you select the folder ('galley folder' for example) which if possible will render out one image from each of its sub folders, kind of like a gallery preview
At the moment it will only display images from a sub folder if that is selected
Display images from media folders
Hi all, I am trying to render one image from each media folder (when the parent folder is selected) the structure is like this
Gallery Folder
I've made a little progress with the below, but it only renders images when a sub folder is selected, does anyone know how I could tweak this to display one image from each folder when the parent is selected please?
Hopefully that makes sense!
Hi Adam,
To check a couple of things, is "Gallery Folder" a folder in the media section rather than content and you have a property on your page that is rendering on the front end that has a media picker on it, you pick a "sub folder" with that picker but you want to render only the first image in that "sub folder"?
Thanks,
Jeavon
Hey Jeavon
Thanks for the reply
Yep 'gallery folder' is a folder in the media section
Yea on the page there is a media picker where you select the folder ('galley folder' for example) which if possible will render out one image from each of its sub folders, kind of like a gallery preview
At the moment it will only display images from a sub folder if that is selected
Ok, how about this:
Awesome! This works perfect thanks a lot
Excellent, you're welcome!
Hello,
I don't know what version you are on, but using the Razor macro's is not the recommanded way of doing things anymore. In v6 you have partial view macro's you can use or switch to MVC. Here is some more info how you can find to check if you're using the old or new Razor: http://our.umbraco.org/projects/backoffice-extensions/digibiz-advanced-media-picker/digibiz-advanced-media-picker/39627-How-to-detect-if-no-items-have-been-picked#comment144735
If you want to use the new Razor to display images from a media folder have a look at the DAMP Gallery. On Page 2 it shows the media of a folder.
Jeroen
Hi Guys,
Here is a version from me.
is working on a reply...