Copied to clipboard

Flag this post as spam?

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


  • Tony Kiernan 278 posts 341 karma points
    Jun 24, 2011 @ 16:56
    Tony Kiernan
    0

    Loop through some of gallery

    So, I'm looping through items in a media folder

    Media gallery = new Media(999);
    foreach (Media pic in gallery.GetDescendants())
    {
    @pic.getProperty("umbracoFile").Value.ToString() }

    Which works fine. However, I want to exclude the top image as that's not going to be in the thumbnail controls.  So, I need to do something along these lines

    foreach (Media pic in gallery.GetDescendants().All().Where(x => x.Position() != 1))

    Obviously this syntax is wrong.  Anyone help?

  • Daniel Bardi 912 posts 2539 karma points
    Jun 24, 2011 @ 17:39
    Daniel Bardi
    0

    You could use an if statement to skip the first item.

  • Tony Kiernan 278 posts 341 karma points
    Jun 26, 2011 @ 19:17
    Tony Kiernan
    0

    Yes, but that's going to give me considerabley more lines of code (once we start bringing in showing the main one larger, handling only one image etc).  I can do what I'm asking easily in xslt, it SHOULD be possible with razor

  • Dan Diplo 1448 posts 5512 karma points MVP 2x c-trib
    Jun 27, 2011 @ 12:28
    Dan Diplo
    0

    You should be able to do something like this using DynamicMedia item:

    @{
      var gallery = new umbraco.MacroEngines.DynamicMedia(999);
    }

    <ul id="gallery">
    @foreach (dynamic item in gallery.Children.Items.Skip(1))
    {
    <li>
    <img src="@item.umbracoFile" alt="@item.name" />
    </li>
    }
    </ul>

    The Skip(1) part just skips the first item in the collection. You can then just access the media item properties directly since it is being used as a dynamic type.

  • Tony Kiernan 278 posts 341 karma points
    Jun 27, 2011 @ 12:59
    Tony Kiernan
    0

    Cool!  Thank you very much.

    Now, will

    gallery.Children.Items.Single(1)

    Just give me the first/main one?

  • Dan Diplo 1448 posts 5512 karma points MVP 2x c-trib
    Jun 27, 2011 @ 15:02
    Dan Diplo
    0

    I think you could just use 

    gallery.Children.Items.First() 
  • Tony Kiernan 278 posts 341 karma points
    Jun 27, 2011 @ 15:08
    Tony Kiernan
    0

    Thank you, again

Please Sign in or register to post replies

Write your reply to:

Draft