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 03, 2015 @ 16:38
    Johan
    0

    Hide navigation menus for 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>
    }
    
  • Bijesh Tank 192 posts 420 karma points
    Dec 03, 2015 @ 17:04
    Bijesh Tank
    0

    Have you set up any member groups?

    Once you have setup member groups then you lock down your content pages using the "Public access" feature.

    Then in your code you can utilise the MemberHasAccess and IsProtected methods. See this post for an example https://our.umbraco.org/forum/developers/razor/53882-@PartialViewMacropage-and-page-protection-status

Please Sign in or register to post replies

Write your reply to:

Draft