Copied to clipboard

Flag this post as spam?

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


  • Andreas 8 posts 28 karma points
    Jun 21, 2012 @ 09:58
    Andreas
    0

    Changing Menu from level 1 to level 2

    Hello, I have a menu which changes color depending on which node its on, still same menu and everything, and the value for CurrentModel.AncestorOrSelf(2) (when debug with breakpoints I get correct value). But I cannot get it to work, whole code (foreach) works just fine for menu (1).

     

    Macroscripts:

    @{var level = 1; if (Helper.IsInMyArea(CurrentModel)) { level = 2; } }
        @foreach (var node in CurrentModel.AncestorOrSelf(level).ChildrenAsList.Where(p => p.GetPropertyValue("umbracoNaviHide") == "0"))  
        { 
    var menuType = node.GetPropertyValue("menuType");
            if (menuType != "Main menu" && menuType != "Main menu and big") { continue; }
            var css = "small"; // <a class="active"
            var selected = Array.IndexOf(CurrentModel.Path.Split(','), node.Id.ToString()) >= 0 ? " class=\"active\"" : "";
            
            if (menuType == "Main menu and big") { css = "big"; }
            
            <a @Html.Raw(selected) href="@node.Url"><div class="left"></div><div class="item @css">@node.Name</div><div class="right"></div></a>
            
        }
    </div>
    <div class="clear"></div>

     

    And my Helper class has following

     

            public static bool IsInMyArea(DynamicNode node)
            {
                var ret = false;
                while (node!=null)
                {
                    if (node.NodeTypeAlias == "MyNetRoot")
                    {
                        ret = true;
                        break;
                    }
                    node = node.Parent;
                }
                return ret;
            }

     

Please Sign in or register to post replies

Write your reply to:

Draft