Copied to clipboard

Flag this post as spam?

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


  • Umbraco 137 posts 294 karma points
    Oct 12, 2011 @ 13:18
    Umbraco
    0

    Create a list of site roots

    I'm using Razor and the DynamicNode and DynamicNodeList. I can easily find the site root for the current node using .AncestorOrSelf(). But I'd like to get a list of all other site roots. 

    Looking at the XML in ~/App_Data/umbraco.config I can see that the site root is actually not a root node in the XML, it's the first child of the actual root node (called 'Root') in the XML, and all other site roots are its siblings. But there is no Siblings() method on DynamicNode. I tried .XPath("following-siblings") but it's empty.

    What would be the best way to get all site roots?

  • Rodion Novoselov 694 posts 859 karma points
    Oct 12, 2011 @ 13:52
    Rodion Novoselov
    0

    Hi. "following-sibling" (not 'siblingS') is an xpath axis, so if you want to use it then the correct syntax would be 'following-sibling::*'. Actually why not to use the .Children collection of the topmost root itself?

  • Umbraco 137 posts 294 karma points
    Oct 12, 2011 @ 14:29
    Umbraco
    0

    Thanks for the tip. I didn't know how to get the CMS Content node (actual root in the XML). Turns out this works:

    new DynamicNode(-1)

    I found the rest of the solution here:

    http://our.umbraco.org/forum/developers/razor/19859-Getting-Rootnode-siblings

     

     

Please Sign in or register to post replies

Write your reply to:

Draft