Copied to clipboard

Flag this post as spam?

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


  • Ben Norman 167 posts 275 karma points
    Nov 05, 2011 @ 01:46
    Ben Norman
    0

    Media List Iteration routine - Missing InGroupsOf on List<DynamicBackingItem>

    I am writing a Media Folder Viewer.

    When I call the ChildrenAsList on a DynamicMedia I get an List<DynamicBackingItem>.

    How do I group the items into groups of 4?

    @using umbraco.MacroEngines;
    @using umbraco.cms.businesslogic.media;
    
    @helper BuildTable(dynamic mediaList)
    {
        <table border="0">
        <tbody>
        @foreach (var item in mediaList)
        {
            <tr>
                <td align="center"><img src="@item.GetProperty("umbracoFile").Value" alt="" /></td>
            </tr>
        }
        </tbody>
        </table>
    }
    @helper BuildTable2(dynamic mediaList)
    {
        <table border="0">
        <tbody>
        @foreach (var group in mediaList.InGroupsOf(4))
        {
            <tr>
            @foreach(var item in group)
            {
                <td align="center"><img src="@((DynamicMedia)item).umbracoFile" alt="" /></td>
            }
            </tr>
        }
        </tbody>
        </table>
    }
    
    @{
        if (String.IsNullOrEmpty(@Parameter.MediaFolder))
        {
            <div>A Folder has not been selected</div>
        }
        var folderId = @Parameter.MediaFolder;
        var media = Model.MediaById(folderId);
        var items = media.ChildrenAsList;
        if(items.GetType() == typeof(DynamicNull))
        {
            <div>Cannot Find the Folder (@folderId)</div>
        }
        else if(items.Count <= 0)
        {
            <div>Folder is Empty</div>
        }
        else
        {
            @BuildTable(items);
        }
    }
    
  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Nov 06, 2011 @ 16:22
    Sebastiaan Janssen
    0

    you should use .Children instead of .ChildrenAsList in this case.

  • Ben Norman 167 posts 275 karma points
    Nov 06, 2011 @ 23:50
    Ben Norman
    0

    thanks, that fixed it.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies