Copied to clipboard

Flag this post as spam?

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


  • Johan 95 posts 264 karma points
    Dec 07, 2015 @ 07:57
    Johan
    0

    Hide navigation from non-logged in users

    I would like to hide some the menus on the navigation that a member has not access to.

    For example if member1 has access to has access to everything then show every menu on the navigation. But if member2 doesn't have access to meny2, -hide it from the navigation

    How can I do this?

    Here is my navigation macro code.

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @{
        int num = 1;    
        var rootNode = CurrentPage.Site();
    
        <ul id="menu">
    
            <li class="thehome">
                <a href="@rootNode.Url" class="drop home"></a>
            </li>
    
    
            @foreach (var mainNode in rootNode.Children().Where("Visible"))
            {
                int childCount = 1;
                int numChildren = mainNode.Children().Count();
    
                <li>
                    <a href="@mainNode.Url" class="drop">@mainNode.Name</a>
    
                    @{
                        var childNodes = mainNode.Children().Where("Visible");
                    }
    
                    @if (childNodes.Any())
                    {
                        <div id=nav-@num class="dropdown_5columns">
    
                            <!-- Begin 2 columns container -->
                            <div class="col_5">
                                <h2>@mainNode.Name</h2>
                            </div>
    
                            @* note if you want ALL descendants change .Children to .Descendats*@
                            @foreach (var childNode in childNodes)
                            {
                                // if first node or new set of three open the div and ul @: is used to stop razor trying to
                                // "balance" the tags
                                if (childCount == 1 || (double)childCount % 3 == 1)
                                {
                                    @:<div class="col-md-4">
                                    @:<ul class="subnav">
                                }
                                <li><a href="@childNode.Url">@childNode.Name</a></li>
    
                                // close the div and list if this is either a multiple of 3 or the last one
                                if ((double)childCount % 3 == 0 || numChildren == childCount)
                                {
                                    @:</ul>
                                    @:</div>
                                }
    
                                childCount++;
    
                            }
    
                        </div>
                    }
    
                </li>
                num++;
            }
        </ul>
    }
    
  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    Dec 07, 2015 @ 08:27
Please Sign in or register to post replies

Write your reply to:

Draft