Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 19:52
    Rylan
    0

    Umbraco 7.6 Media Folder Gallery

    I created a media picker called galleryFolder, and I want to be able to grab the folder and all it's children to be displayed in a gallery on page.

    This doesn't seem to work anymore:

        @{
                      ViewBag.mediaFolderId = CurrentPage.galleryFolder;
                      if(ViewBag.mediaFolderId != null && ViewBag.mediaFolderId.ToString() !=""){
                            var gallery = Umbraco.Media(ViewBag.mediaFolderId);
                             foreach(dynamic item in gallery.Children){
                                    <a href="@item.Url">
                                        <img src="@item.Url" alt="@item.Name" /> 
                                    </a>
                                }
                      }
                }
    

    Not sure what exactly to do since the media pickers have changed since now we call images like this.

    if(CurrentPage.HasValue("mainImage")){
        var pgImg = CurrentPage.mainImage;
        <img src="@pgImg.Url" alt="pgImg.Name" />
    }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 20:25
    Alex Skrypnyk
    1

    Hi Rylan

    Since Umbraco 7.6 'Property Value Converters' are part of the Core, so now you can call media item directly from content node, without defining ID and creating media object like it was before. Read about this change -

    https://our.umbraco.org/documentation/getting-started/setup/upgrading/760-breaking-changes#property-value-converters-u4-7318

    It's easier to work with media now ) just get it from node, like you did it :

    var pgImg = CurrentPage.mainImage;
    

    Thanks,

    Alex

  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 20:44
    Rylan
    0

    Thanks Alex,

    I wish I knew how to take that in effect to make a whole gallery pull from a media folder though. I am trying and can't seem to get it to work! I'm more of a front-end developer and don't have the widest MVC knowledge.

    This definitely isn't working though.

                    @if(CurrentPage.HasValue("galleryFolder")){
                    var images = CurrentPage.galleryFolder;
                    var imgSpot = images.Children;
                    foreach (var img in imgSpot)
                    {
                        <img src="@img.Url" alt="img.Name" />
                    }
                }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 20:54
    Alex Skrypnyk
    1

    Hi Rylan

    Is EnablePropertyValueConverters set to true in your solution?

    CurrentPage.galleryFolder - returns folder or Id of folder?

    What is the error of this code?

    Alex

  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 21:11
    Rylan
    0

    Yes, I checked if it's enabled to true, and it is. When I use:

    @CurrentPage.galleryFolder

    I get the folder ID. Just not sure what to do after this.

    Thanks,

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 21:16
    Alex Skrypnyk
    0

    If there ID then try this code:

    @if (CurrentPage.HasValue("galleryFolder"))
    {
        var imageFolderId = CurrentPage.galleryFolder;
        var imageFolder = Umbraco.Media(imageFolderId);
        var images = imageFolder.Children;
        foreach (var img in images)
        {
            <img src="@img.Url" alt="@img.Name" />
        }
    }
    
  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 21:31
    Rylan
    0

    No longer getting an error but nothing is populating, unfortunately.

    enter image description here

    enter image description here

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 21:35
    Alex Skrypnyk
    100

    Rylan, lets try to use strongly typed models and the same code will look like:

    @if (Umbraco.AssignedContentItem.HasValue("galleryFolder"))
    {
        var imageFolder = Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("galleryFolder");
        var images = imageFolder.Children;
    
        foreach (var img in images)
        {
            <img src="@img.Url" alt="@img.Name" />
        }
    }
    
  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 21:38
    Rylan
    0

    enter image description here

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 21:39
    Alex Skrypnyk
    0

    Rylan, row was:

    var imageFolder = Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("galleryFolder");
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 21:39
    Alex Skrypnyk
    0

    Don't remove "IPublishedContent"

  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 21:47
    Rylan
    0

    Must of somehow copied wrong when I copied it from email. Still error though: enter image description here

  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 21:50
    Rylan
    1

    I'm going to try changing the alias name and see if that helps, because I did change the alias to a different type originally and it looks like it may be cached.

  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 21:55
    Rylan
    1

    Yup finally working, must be a glitch with changing alias types to another. It seems to have cached irregularly on the server.

    Deleting the alias, creating a whole new one seemed to work.

    Thanks Alex.

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    May 12, 2017 @ 21:59
    Alex Skrypnyk
    0

    Wow, cool, glad that we solved it!

    Have a nice weekend, Rylan.

    Alex

  • Rylan 67 posts 251 karma points
    May 12, 2017 @ 22:01
    Rylan
    0

    You as well.

  • Jeavon Leopold 3072 posts 13628 karma points MVP 10x admin c-trib
    May 15, 2017 @ 10:03
    Jeavon Leopold
    0

    FYI, there should be no need for Umbraco.AssignedContentItem (it will work but is going to have a overhead) replace with Model.Content and this should continue to be fine

  • Rylan 67 posts 251 karma points
    Feb 01, 2018 @ 19:02
    Rylan
    0

    I'm having issues using this with Merchello Fast Track. It works, but then when I publish another page it breaks a different page with the gallery. Is it possible the code is not rendering it's actual page properly?

    Code:

        @if(Model.HasValue("galleryFolder"))
                            {
                                var ImagesLists = Umbraco.AssignedContentItem.GetPropertyValue<IPublishedContent>("galleryFolder");
                                var Collections = ImagesLists.Children;
                                foreach (var gimage in Collections)
                                {
                                    <div class="col-sm-3 col-xs-4"><a href="@gimage.Url" class="gallery-content" data-lightbox-type="inline" data-lightbox-gallery="ProductImage"><img src="@gimage.Url" alt="" /></a></div>
                                }
                            } 
    

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft