Hide menu (left-side navigation bar) from unauthenticated users

@kmwil & @jbd,

Using a fresh Grav v1.7.31 install, try the following:

  • Add the following to page header of 02.typography/default.md

    login:
      # The following will mark page as invisible for users without access rights
      visibility_requires_access: true
    access:
      # Page is only visible to logged-in users
      site.login: true
    

    Note:

    • Above settings can be set using Admin in the Security tab of a Page
  • Create file /user/config/plugins/login.yaml and add:

    dynamic_page_visibility: true
    

    Note:

    • This can be set using Admin in the config of plugin Login
    • See README of plugin Login
  • Open site in browser.

  • If not logged in, page Typography will not be visible in menu.

Note:

  • Above behaviour for page Typography will work for any collection using filter visible e.g. {% for p in page.children.visible %}.

@jbd,

It’s misleading that the Grav admin GUI states “Set to Yes if page should be shown in menus only if user can access them.” which is not true.

The help statement in Admin is correct, but I admit a reference to the Login setting might be helpful.

NB.
The first item of a quick search for visibility_requires_access using Google led to the answer… Tip: Add Search as standard tool to your toolbelt. :wink:

2 Likes