Copied to clipboard

Flag this post as spam?

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


  • Rob 43 posts 79 karma points
    Dec 19, 2012 @ 23:47
    Rob
    0

    Get more than one document type?

    Assuming I want to get all InfoItem and NewsItem documents, sort by date and return the to 5 items.

    Combine with that - that the documents can hang at any level or off any node in the site..Is that possible?

    Currently if i want to get all the NewsItems nodes - starting at the websites root, i would use the following foreach loop (parent is set to AncestorOrSelf(1) 

    foreach (var node in parent.DescendantsOrSelf("NewsItem").Take(5)) 

    So I guess what i am looking for is something like 

    foreach (var node in parent.DescendantsOrSelf("NewsItem||InfoItem").OrderBy("docDate desc").Take(5)) 

    (any other ideas as to how to pull this off would be appreciated also)

    Thanks in advance.

     

    Rob

  • Braydie 148 posts 346 karma points
    Dec 24, 2012 @ 16:35
    Braydie
    100

    Hi Rob,

    I'd do something like this:

    var Homepage = Node.Ancestorys().FirstOrDefault(x=>x.NodeTypeAlias.Equals("HomepageDocType")); // Get your homepage or root of site

    string[] DocTypes = new string[]{ "NewsItem", "InfoItem" }; // The document types you want to get

    var Items = Homepage.Descendants().Where(n=> DocTypes.Contains(n.NodeTypeAlias))
    .OrderByDescending(x=>x.GetPropertyValue("docDate")).Take(5);

    foreach(var Item in Items)
    {
    //loop over your nodes

    The GetPropertyValue is an extension method that wraps Node.GetProperty(Alias) with some null checking.

    Hopefully this sets you in the right direction!

  • Rob 43 posts 79 karma points
    Dec 25, 2012 @ 00:04
    Rob
    0

    Nice!.. I will need to give it a try.

    I ended up building something functional with a .net usercontrol, but if prefer the razor syntax when it works. (less of a deployment head ache)

    Rob

Please Sign in or register to post replies

Write your reply to:

Draft