Copied to clipboard

Flag this post as spam?

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


  • René Andersen 238 posts 684 karma points
    Jul 02, 2015 @ 08:19
    René Andersen
    0

    Show all images from every childpage

    Hi everybody

    I ran into a problem using the multiple media picker.

    I have this website structure:

    Website structure

    In "Galleri One + Two" I use the multiple media picker to choose images. I can manage to show the images from "Galleri One", but how can I show images from both "Galleri One + Two" on the same page? I want to show all images and then the visitor can sort the images by clicking on buttons with the names "Galleri One + Two".

    My code that shows the images from "Galleri One" looks like this:

    @{ 
    var pictures = CurrentPage.Down(1);
    }
    
    @if (pictures.HasValue("testImages"))
    {
      var caseStudyImagesList = pictures.testImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
      var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList);
    
      foreach (var caseStudyImage in caseStudyImagesCollection)
      {
        <img src="@caseStudyImage.Url" style="width:300px;height:300px" />
      }
    }
    

    Thanks in advance!

    // René

  • Urvish 252 posts 776 karma points
    Jul 02, 2015 @ 08:30
    Urvish
    0

    Hi Rene,

    If you are on the Galleri page then you can get the images list by using its children.

    And on the galleri one page you can have the sibling of that node.

    So you can loop through siblings and get images.

    For Ex:

    foreach (IPublishedContent item in currentNode.Siblings()) { var caseStudyImagesList = item.GetProperty("image"); }
    

    Hope this will help.

    Regards, Urvish Mandaliya

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 02, 2015 @ 09:08
    Dennis Aaen
    100

    Hi René

    From the code in your post it looks to me that the current page is gallery and then you want to loop though the children and display the images in a property that uses the multiple image picker.

    This code below should do exactly what you are trying to do.

    @{ 
    var items = CurrentPage.Children;
    }
    
    
    @foreach(var pictures in items.Where("Visible")){  
    
        if (pictures.HasValue("testImages"))
        {
          var caseStudyImagesList = pictures.testImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
          var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList);
    
          foreach (var caseStudyImage in caseStudyImagesCollection)
          {
            <img src="@caseStudyImage.Url" style="width:300px;height:300px" />
          }
        }
    }
    

    Hope this helps, and make sense.

    /Dennis

  • René Andersen 238 posts 684 karma points
    Jul 02, 2015 @ 09:18
    René Andersen
    0

    Hi Dennis

    I could just copy in your code and it worked perfectly.

    Thank you!

    // René

Please Sign in or register to post replies

Write your reply to:

Draft