Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Apr 06, 2015 @ 17:43
    Steve
    0

    Where Visible Not Working Correctly

    I have dynamic navigation using the Razor below, but for some reason the if statment that includes Where("Visible") is not working. These children still show up in the navigation. Suggestions?

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
    var StartLevel = String.IsNullOrEmpty(Parameter.startLevel) ? 4 : int.Parse(Parameter.startLevel);
    var FinishLevel = String.IsNullOrEmpty(Parameter.finishLevel) ? 6 : int.Parse(Parameter.finishLevel);
    var page = Model.AncestorOrSelf(StartLevel);
    
        if(page != null)
        {
        <h2>
            <a href="@page.url">@page.name</a>
        </h2>
        @traverse(page, StartLevel, FinishLevel);   
        }                
    }   
    
    @helper traverse(dynamic page, int StartLevel, int FinishLevel)
    {
        <ul class="nodeList list-aside">
            @foreach (var node in page.Children.Where("Visible && NodeTypeAlias == \"AboutRoseLevel4Page\" || NodeTypeAlias == \"ExternalLink\" || NodeTypeAlias == \"AboutRoseVoices\" || NodeTypeAlias == \"PresidentsHomePage\" || NodeTypeAlias == \"PresidentsInternalPage\""))
                {
                var itemName = node.HasValue("shortPageTitle") ? @node.shortPageTitle : node.HasValue("pageTitle") ? @node.pageTitle : @node.pageName;
                var levelOne = node.IsAncestor(Model) ? "class=levelOne" : "";
                var childActive = node.IsEqual(Model) ? "class=activeChild" : "";
                var target = node.externalUrl ? "target=_blank" : "";
                var link = node.HasValue("externalUrl") ? node.url : node.Url;
                <li @childActive @levelOne ><a href="@link" @target>@itemName</a>
        @if(node.Children.Where("Visible && NodeTypeAlias == \"AboutRoseLevel4Page\" || NodeTypeAlias == \"ExternalLink\" || NodeTypeAlias == \"AboutRoseVoices\" || NodeTypeAlias == \"PresidentsHomePage\" || NodeTypeAlias == \"PresidentsInternalPage\"").Count() > 0 && node.IsAncestorOrSelf(Model) && node.Level <= FinishLevel)
              { 
              @traverse(node, StartLevel, FinishLevel);
              }
                </li>
              }
        </ul>     
    }
  • Amir Khan 1282 posts 2739 karma points
    Apr 06, 2015 @ 17:56
    Amir Khan
    101

    Hi Steve, assuming you have the umbracoNaviHide property on the page in question and it is checked? Does it work if you separate the visible statement from the rest like below?

    Children.Where("Visible").Where("NodeTypeAlias!= \"AboutRoseLevel4Page\"")

     

    -Amir

  • Steve 472 posts 1216 karma points
    Apr 06, 2015 @ 18:11
    Steve
    0

    Amir, Thanks! that was it! Works fine once I add the second "Where()." I don't think I've ever had problems with this syntax before, but I will have to go check some of my other navigation to assure it is functioning properly now. I still don't understand why it doesn't take this format though:

    Children.Where("Visible && NodeTypeAlias == \"Category2InternalPage\"");

    Thanks again!

Please Sign in or register to post replies

Write your reply to:

Draft