Copied to clipboard

Flag this post as spam?

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


  • Jon Ivar Nielsen 24 posts 96 karma points
    Nov 08, 2011 @ 11:37
    Jon Ivar Nielsen
    0

    Finding tree nodes in Razor

    I am new to Umbraco (and Razor) and I have a question regarding the Content tree. Just below the content tree topmost node (Content), I have two child nodes. The first is the top node of the site tree and the second node is the top node of a rotator image collection.

    On my home page I need to access the top node in the rotator tree. I have seen xslt code that does this but I need the Razor code. Anyone?

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 08, 2011 @ 11:43
    Dirk De Grave
    0

    Hi Jon,

    Here's code snippet to get you started:

    @{ 
      var rotatorImageCollectionNode = 1234;
      <ul>
      @foreach (dynamic node in Model.NodeById(rotatorImageCollectionNode).Children) {
        <li>@node.Name</li>
      }
      </ul>
    }

    Could also pass in the node id as a parameter, or it can be set as a property on the home page (content picker). Up to you to decide what method fits best.

     

    Cheers,

    /Dirk

  • Jon Ivar Nielsen 24 posts 96 karma points
    Nov 08, 2011 @ 21:05
    Jon Ivar Nielsen
    0

    Thanks Dirk

    Great and simple solution(s).

    :o)
    Jon Ivar

Please Sign in or register to post replies

Write your reply to:

Draft