Copied to clipboard

Flag this post as spam?

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


  • Yuxuan Li 12 posts 122 karma points
    Jul 04, 2016 @ 07:18
    Yuxuan Li
    0

    Hi All,

    How to use Razor create a dynamic sidebar navigation (Vertical)? And I want to make the start node is level 2 or level 3. For example, my site is like the following:

    • Home
    • Service 1
      • Sub Service 1
      • Sub Service 2
      • Sub Service 3
    • Service 2

    For example. when I in the page (Service 1), I want my side bar nav looks like:

    • Service 1
      • Sub Service 1
      • Sub Service 2
      • Sub Service 3

    Thanks a lot!

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jul 04, 2016 @ 07:33
    Michaël Vanbrabandt
    100

    Hi Yuxuan Li,

    if you only want to display the navigation on the service pages you can do something like this:

    <ul>
    
    @foreach(var child in Model.Content.Children)
    {
        <li><a href="@child.Url">@child.Name</a></li>
    }
    
    </ul>
    

    If you also want to display it on the child pages:

    <ul>
    
    @foreach(var child in Model.Content.AncestorOrSelf("servicePageAlias").Children)
    {
        <li><a href="@child.Url">@child.Name</a></li>
    }
    
    </ul>
    

    /Michaël

  • Yuxuan Li 12 posts 122 karma points
    Jul 06, 2016 @ 01:23
    Yuxuan Li
    0

    Thanks Michael! That works.

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Jul 06, 2016 @ 07:30
    Michaël Vanbrabandt
    0

    No problem glad I could help

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft