Copied to clipboard

Flag this post as spam?

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


  • Adriano Fabri 469 posts 1633 karma points
    May 03, 2012 @ 01:57
    Adriano Fabri
    0

    How to get last nodes of a news tree with Razor?

    Hi to all,
    I have this tree node structure:

    News
       |
       Year Folder
           |
           Month Month
                |
                News Page 1
                News Page 2
                News Page 3

    I want to get all News Pages nodes without the Year and the Month Folders.

    In XLST I used this code to get only the "last" nodes:

    <xsl:variable name="matchedNodes" select="umbraco.library:GetXmlNodeById($source)[@isDoc][last()]/* [@isDoc]"/>

    How can I do that with Razor?

    I don't want to use a "visible" field to hide the Years and Months Folders and I don't want to filter on specific nodeTypeAlias.
    I want to use a generic code so it can be reused also for other tree with same or similar structure but different documentType (for example events, products, etc.).

    Thank you in advance
    Adriano

  • Owen 123 posts 246 karma points
    May 03, 2012 @ 08:16
    Owen
    0
    var source = new DynamicNode(id);
    var matchNodes = source.Descendants(d=>!d.ChildrenAsList.Any())
  • Adriano Fabri 469 posts 1633 karma points
    May 03, 2012 @ 09:34
    Adriano Fabri
    0

    Hi Owen,
    thank you for your answer.
    I tried your code but I receive this error:
    "error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type"

    Adriano

  • Adriano Fabri 469 posts 1633 karma points
    May 03, 2012 @ 09:48
    Adriano Fabri
    0

    I solved...I need to convert DynamicNode in DynamicNodeList to use it in my code. :-)

    Best Reguards

    Adriano

  • Adriano Fabri 469 posts 1633 karma points
    May 03, 2012 @ 11:29
    Adriano Fabri
    0

    Hi Owen,
    I checked the result but the code function partially.

    When I print the nodes, I don't see the Years Folders (correct) but I see the News Pages and also the Months Folders (wrong)

    I need to print only the News Pages (last nodes) but I wish it were only seen the news.

    Adriano

Please Sign in or register to post replies

Write your reply to:

Draft