Copied to clipboard

Flag this post as spam?

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


  • adam 14 posts 74 karma points
    Aug 01, 2013 @ 01:01
    adam
    0

    2nd level navigation

    I found the code below on another topic to do a 2nd level navigation, but its giving me a really odd error:

    c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\d4850de4\c311c2c8\AppWeb635108881622787274_mainnavnew.cshtml.70df5e80.g7kslbm9.0.cs(212): error CS1513: } expected

    Does anyone know if there is something wrong with the script or has something gone wrong elsewhere?

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
      var startLevel = 1;
      var finishLevel = 2;  
      var parent = @Model.AncestorOrSelf(startLevel);
      if (parent != null) { @ulMenu(parent, startLevel, finishLevel) ; }
    }
    
    @helper ulMenu(dynamic parent, int startLevel, int finishLevel){
    
    <ul @Html.Raw(ulClass)>
    
    @foreach (var node in parent.Children.Where("Visible")) {
        <li>
            <a href="@node.Url">@node.Name</a>                                      
    
            @if (@node.Level <= finishLevel) { @ulMenu(node, startLevel, finishLevel); } 
    
        </li>
    }
     </ul>    
    }  
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 01, 2013 @ 08:50
    Jeavon Leopold
    0

    Hi Adam,

    There are a few extra @ that need to be removed, in Umbraco v4 they were forgiven but in v6 they are not.

    Try

     @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var startLevel = 1;
      var finishLevel = 2;  
      var parent = Model.AncestorOrSelf(startLevel);
      if (parent != null) { 
            @ulMenu(parent, startLevel, finishLevel)  
            }
    }
    
    @helper ulMenu(dynamic parent, int startLevel, int finishLevel){
    
    <ul @Html.Raw(ulClass)>
    
    @foreach (var node in parent.Children.Where("Visible")) {
        <li>
            <a href="@node.Url">@node.Name</a>                                      
    
            @if (node.Level <= finishLevel) { 
            @ulMenu(node, startLevel, finishLevel)
            } 
    
        </li>
    }
     </ul>    
    }  
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 01, 2013 @ 11:46
    Jeavon Leopold
    0

    It looks like you are also missing a declaration of the ulClass, maybe it should be like:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{
      var startLevel = 1;
      var finishLevel = 2;  
      var parent = Model.AncestorOrSelf(startLevel);
      if (parent != null) { 
        @ulMenu(parent, startLevel, finishLevel, "")  
      }
    }
    
    @helper ulMenu(dynamic parent, int startLevel, int finishLevel, string ulClass){
        <ul @Html.Raw(ulClass)>
            @foreach (var node in parent.Children.Where("Visible")) {
                <li>
                    <a href="@node.Url">@node.Name</a>                                      
                    @if (node.Level <= finishLevel) { 
                        @ulMenu(node, startLevel, finishLevel, "")
                    } 
                </li>
            }
        </ul>    
    }  
    
  • adam 14 posts 74 karma points
    Aug 10, 2013 @ 20:29
    adam
    0

    Thanks a lot for the reply the above is rendering all the links in an li each which wouldnt work for a dropdown navigation

    So I've got this which renders out the dropdown correctly but its rendering every single page

    Is there a way so the main navigaiton isnt popuplated unless a true/false option is checked i.e. show in navigation?

    @inherits umbraco.MacroEngines.DynamicNodeContext
    <ul class="myMenu">
        <li><a href="/">Home</a> </li>
        @foreach (var page in @Model.AncestorOrSelf(1).Children)
        {
            string style = "";
            if (Model.Id == page.Id) { style = "class=\"current\""; }
            <li>
                <a href="@page.Url" @Html.Raw(style)>@page.Name</a>
    
                @if (page.Childen != null && page.Children.Count() > 0)
                {
                    <ul>
                    @foreach (dynamic secondPage in page.Children)
                 {
                        <li>
                     <a href="@secondPage.Url">@secondPage.Name</a>
                        </li>
                    }
                    </ul>
                }
            </li>
        }
    </ul>
    
  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Aug 11, 2013 @ 09:07
    Jeavon Leopold
    100

    Yes, but normally this is done in reverse, add a property called "Hide in navigation" with the alias of "umbracoNaviHide" and tick the pages you want to hide, then

    @foreach (var page in @Model.AncestorOrSelf(1).Children.Where("Visible"))
    
  • adam 14 posts 74 karma points
    Aug 11, 2013 @ 18:49
    adam
    0

    Brilliant thanks!

Please Sign in or register to post replies

Write your reply to:

Draft