Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1282 posts 2739 karma points
    Nov 30, 2011 @ 16:00
    Amir Khan
    0

    List pages at defined level

    Hi,

    I'm trying to pull some content out of documents at a specific level, I'm struggling to get the documents at just that level and not the level above also...I'm also having problems grabbing the document properties out of the pages at the correct level.

    Here's my document structure:

    Home
    Gallery
      Project Folder (commercial)
          Project 1
          Project 2

      Project Folder (residential)
          Project 1
          Project 2

    Here's the code I'm using so far:

    @*
    LIST CHILDREN BY TYPE
    =================================
    This snippet shows how simple it is to fetch only children of a certain Document Type using Razor. Instead of
    calling .Children, simply call .AliasOfDocumentType (even works in plural for readability)! 
    For instance .Textpage or .Textpages (you can find the alias of your Document Type by editing it in the 
    Settings section).

    NOTE: It is safe to remove this comment (anything between @ * * @), the code that generates the list is only the below!
    *@
        @foreach (var item in @Model.Children.Where("Visible"))
        {
        
          <div class="galleryThumbMosaic-block galleryThumb-bar">
          <a class="mosaic-overlay" href="@item.Url">
            <div class="galleryThumb-details">
              <h2 class="projectTitle">@item.Url</h2>
              <span class="projectDate">@item.projectDate</span><span class="projectCategory">@item.Name</span>
            </div>
          </a>
          <a href="@item.Url" class="mosaic-backdrop"><img src="@Model.getProperty("thumbnailImage")" width="240" height="150" alt="placeholder"></a>
          </div>
    }

    Thanks!

    Amir

    
    
    

     

  • Amir Khan 1282 posts 2739 karma points
    Nov 30, 2011 @ 16:42
    Amir Khan
    0

    Also, how would I go about grabbing the 1st document from folder 1, then the first from folder 2, then the 2nd from folder 1, etc?

     

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Nov 30, 2011 @ 17:53
    Dan Diplo
    0

    To get all nodes at a given level you can access the Level propety of each dynamic node. So you could do this:

    @foreach (var item in Model.Descendants().Where("Visible").Where("Level == 2"))

    Check out http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets for more info on how to use Razor.

    PS. I resisted the urge to making any boxing jokes :D

  • Amir Khan 1282 posts 2739 karma points
    Nov 30, 2011 @ 22:17
    Amir Khan
    0

    Thanks Dan!

  • Tobias Lopez 64 posts 210 karma points
    Feb 03, 2012 @ 10:26
    Tobias Lopez
    0

    Hi, i got this snippet

    foreach (var item in @DynamicModel.Descendants.Where("Level == 2"))
        {
            <p>@item.Id</p>
            <p>@item.Name</p>
        }

    It gives nothing out.

    Any solution?

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 03, 2012 @ 14:59
    Dan Diplo
    0

    Tobias, are you using Umbraco 5? It has a different API so not everything works the same as 4. Your best asking in the Umbraco 5 forum.

  • Amir Khan 1282 posts 2739 karma points
    Feb 06, 2012 @ 21:51
    Amir Khan
    0

    Hey Dan, do you know how i could go about grouping with this method? I'm trying to insert a div every 12th item using the code below, but it returns blank.

     


       @foreach (var node in Model.Descendants.InGroupsOf(12).Where("Visible").Where("Level == 4").OrderBy("SortOrder desc"))    {
        <div class="galleryBlock">
                                                                                                                                  @foreach(var item in node){
          <div class="galleryThumbMosaic-block galleryThumb-bar">
          <a class="mosaic-overlay" href="@node.Url">
            <div class="galleryThumb-details">
              <h2 class="projectTitle">@Library.Coalesce(node.navigationDisplayName, node.Name)</h2>
              <span class="projectDate">@node.projectDate</span><span class="projectCategory">@node.Parent.Name</span><span class="projectPlus">+</span>
            </div>
          </a>
          <div href="#" class="mosaic-backdrop"><img src="@node.Media("thumbnailImage","umbracoFile")" width="240" height="150" alt="@node.Name"></div>
          </div>
    }
    </div>
    }
  • Amir Khan 1282 posts 2739 karma points
    Feb 06, 2012 @ 22:13
    Amir Khan
    0

    Got it!

     

    @foreach(var group in Model.Descendants().OrderBy("UpdateDate").Where("Level == 4").InGroupsOf(12))
    {
       <div class="galleryBlock">
          @foreach(var item in group)
          {
             <div class="galleryThumbMosaic-block galleryThumb-bar">
          <a class="mosaic-overlay" href="@item.Url">
            <div class="galleryThumb-details">
              <h2 class="projectTitle">@Library.Coalesce(item.navigationDisplayName, item.Name)</h2>
              <span class="projectDate">@item.projectDate</span><span class="projectCategory">@item.Parent.Name</span><span class="projectPlus">+</span>
            </div>
          </a>
          <div href="#" class="mosaic-backdrop"><img src="@item.Media("thumbnailImage","umbracoFile")" width="240" height="150" alt="@item.Name"></div>
          </div>

          }
       </div>
    }
  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Feb 07, 2012 @ 10:01
    Dan Diplo
    0

    That's it, Amir! Basic rule is that you perform grouping after all other filters. Same (usually) goes for things like Take() and Skip().

Please Sign in or register to post replies

Write your reply to:

Draft