Copied to clipboard

Flag this post as spam?

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


  • Bijesh Tank 192 posts 420 karma points
    Aug 28, 2012 @ 13:04
    Bijesh Tank
    0

    Razor sidebar nav

    Hi,

    I need to create a sidebar nav but having a bit of trouble writing it with razor. My content structure is as follows:

    - Home
    -- Promos
    --- Promo 1 Details
    ---- About
    ---- Terms and Conditions

    What I am trying to do is produce a sidebar nav like the below for Promo 1 and for it's child pages

    *Promo 1 Details
    *About
    *Terms and Conditions

    Any tips? I know I can do this in XSLT but trying to use Razor instead

    Using Umbraco 4.8.1

    Cheers,
    Bij

  • Fuji Kusaka 2203 posts 4220 karma points
    Aug 28, 2012 @ 13:12
    Fuji Kusaka
    0

     

    Hi Bijesh, 

    Here you go

    @{ 
        var StartNode = Model.NodeById(1200);   
        foreach(dynamic page in StartNode.Children.Where("Visible")){              
             <li>
              @if(page.Children.Count() > 0){
                            <ul>
     @foreach(dynamic childPage in page.Children.Where("Visible")){
                                       if (childPage.Children.Count() > 0)   {
                                             <a href="@firstChildUrl">@childPage.Name</a>
                                       }    
                                  }             
                             </ul>
                     }  
           }
      }

     

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 28, 2012 @ 13:15
    Dirk De Grave
    0

    HI,

    me thinks this should work if you just want to list all descendants (from what I assume looking at your output) regardless of nested structure

    @{
      var promoNode = new DynamicNode(<id of Promos node>);
      var descendants = promoNode.Descendants();
      <ul>
      foreach(var descendant in descendants)
      {
      <li>@descendant.Name</li>
      }
      </ul>
    }

    Cheers,

    /Dirk

  • Bijesh Tank 192 posts 420 karma points
    Aug 28, 2012 @ 13:24
    Bijesh Tank
    0

    Is there a way to do it so that the ID of the node does not need to be input? For example, Self ?  s there will be multiple Promo nodes with child pages.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 28, 2012 @ 13:35
    Dirk De Grave
    0

    yup, use Model.Id (equivalent to $currentPage/@id)

  • Bijesh Tank 192 posts 420 karma points
    Aug 28, 2012 @ 15:33
    Bijesh Tank
    0

    Still not getting the right result. I can't seem to get the 3rd and 4th level items to appear under one nav (as in my example above). When I am on the 3rd level node (i.e. Promo 1 Details), it shows the child nodes but not itself. When I go to the 4th level node (i.e. About or Terms and Conditions), no items are returned.

    - Home
    -- Promos
    --- Promo 1 Details    <-- 3rd level
    ---- About <-- 4th level
    ---- Terms and Conditions<-- 4th level

    Hope this makes sense?

Please Sign in or register to post replies

Write your reply to:

Draft