Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Mar 27, 2012 @ 19:20
    Fuji Kusaka
    0

    Get top level hightlighted

    Hi Guys,

    I very new to razor and actually loving it. I have some issues with  a very simple navigation. 

    <ul id="navi">
      @{
       var naviNode Model.NodeById(1111);
       var groupNode Model.AncestorOrSelf(1);
       const string selectedClass " class=\"current\"";
        bool hasSubNav true;  
      }
      
      <li><href="/">Home</a></li>
      @foreach(var page in  naviNode.Children.Where("Visible"))
      {
       
         <li@Library.If(page.IsAncestorOrSelf(Model)selectedClass)>
             <href="@page.Url" title="@page.Name">@page.Name</a>   
       </li>
     
     }
    </ul>



    Everything is working as expected but somehow i would also like the Home link inherit the class selected whenever am on the root node.

    //fuji


     

     

     

     

     

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 03, 2012 @ 19:09
    Fuji Kusaka
    0

    For some of you who might be looking for something like that in razor, here is the solution. Very simple though.

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.MacroEngines;

    <ul id="group-navi">

      @{
       var terraNode = Model.NodeById(1111);
       var groupNode = Model.AncestorOrSelf(1);
       const string selectedClass = " class=\"current\"";
        bool hasSubNav = true
       
       
       <li@Library.If(Model.NodeTypeAlias == "Group", selectedClass)><a href="/">@groupNode.Name</a></li>
        
        foreach(var page in terraNode.Children.Where("Visible"))
          {
               
                 <li@Library.If(page.IsAncestorOrSelf(Model), selectedClass)>
                     <a href="@page.Url" title="@page.Name">@page.Name</a>   
               </li>
             
             }
          
        
      
      

    </ul>

    //fuji

Please Sign in or register to post replies

Write your reply to:

Draft