Copied to clipboard

Flag this post as spam?

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


  • Libin Joseph 9 posts 31 karma points
    Oct 04, 2013 @ 19:35
    Libin Joseph
    0

    Get sibling nodes in razor

    Hello,

    How do i get all the sibling nodes of a particular node using razor

    Use Case:

    Lets say that I am in a page named Package 1 and Package 1 is a child node of HomeCleaning. My requirement is to find all the child nodes of HomeCleaning, including Package1 and then list the property name "Package Name" in this page.

    ScreenShot of Contents Page

     

    I have tried different options to get the template code using razor. But none of them have worked. This is the last one that I have worked on.

          <ul id="sidebarMenu">

    @{

    Node node = Node.GetCurrent();

    var siteRoot = CurrentPage.Ancestors();

    var child = siteRoot.Children;

    foreach (var item in child)

    {

    <li><a href="">@item.packageName</a></li>

    }

    }

    </ul>

     

    Any help is much appreciated.

     

    Thank you, 

    Libin

     

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Oct 04, 2013 @ 20:56
    Kevin Jump
    0

    I assuming Umbraco6 - but you should just need to go up to the CurrentPage parent, and then list all children

    @{ 
    
        var parent = CurrentPage.Parent;
    
        <ul>
        foreach( var item in parent.Children().Where("Visible"))
        {
            <li>@item.packageName</li>
        }
        </ul>
    
    }
    
  • Libin Joseph 9 posts 31 karma points
    Oct 04, 2013 @ 21:46
    Libin Joseph
    0

    Thank you. that works absolutely great. Is there any good documentation that I can refer to know more about Umbraco nodes and models. Its a bit confusing for me

  • Kevin Jump 2343 posts 14890 karma points MVP 8x c-trib
    Oct 04, 2013 @ 21:50
    Kevin Jump
    0

    Everything I know started here http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets it's a bit old but gives you the basics.

    Then the core documentation is starting to take shape for MVC Stuff.. http://our.umbraco.org/documentation/Reference/Templating/

    and the PDF cheatsheets are handy. http://our.umbraco.org/projects/developer-tools/umbraco-v6-mvc-razor-cheatsheets

  • Charles Afford 1163 posts 1709 karma points
    Oct 06, 2013 @ 23:01
    Charles Afford
    0

    Libin Are you in  razor view?  You should be able to do @Model.children?  Any way i would write the code as

     

    @{ 
    Node node = Node.GetCurrent();
        <ul>
        foreach(string item in node.parent.Children().Where("Visible"))
       
    {
           
    <li>@item.packageName</li>
        }
        </
    ul>

    }
     
Please Sign in or register to post replies

Write your reply to:

Draft