How do I Hide Public pages from view on Login pages?

I have an app where 99% of it requires users to be logged in, BUT there are a few pages (Scene_33,  Scene34, & Scene_36) that are embedded in a public site so their page tabs naturally show up on Login Pages even before users have logged in...

 

Just for cleanness, I need a way to hide the page menu from just the login pages.  Any ideas?

Is this not what you are looking for:

https://support.knack.com/hc/en-us/articles/225372267-Page-Menu-Videos-#hide-individual-links

Is this not what you are looking for:

https://support.knack.com/hc/en-us/articles/225372267-Page-Menu-Videos-#hide-individual-links

Your welcome Anthony !

Works perfectly!  You're a genius!  Thank you!

Hello Anthony,

try below code 


$(document).on('knack-view-render.any', function (event, view, data) {
if(Knack.getUserAttributes()=="No user found")
$("#app-menu-container").hide();
else
$("#app-menu-container").show();
});

if not work then you need to share your app with me or mail me 

 

Thanks,

Sunny Singla

ssingla1985@gmail.com

+919855089359

Hi Sunny or anyone. Please help a noob out. Two questions:

(1) This is CSS, right? Not Javascript?
(2) Where do I enter the page I want to be hidden from the menu? What do I enter? The URL for the page?

I need this as a workaround to the fact that you cannot create “Rules” to hide content on public pages. I want a public “news” page and a members-only news page that contains the public articles and member-restricted articles. Of course I can create a separate members-only page, but then I need to hide the public page from the main menu when the user is logged in. Thank you!

Hi @Katelyn,

Here’s a solution specific to your needs:

  1. Create a public Articles page (scene_xx)
  2. Create a login-protected Member Articles page with URL ‘member-articles’, and hide it in the page menu
  3. Add this code to your Knack JavaScript editor, replacing scene_xx with your public page scene key, and change the member-articles URL slug if need be.
Knack.router.on('route:viewScene', function(slug, search) {

  const currentScene = Knack.getCurrentScene();
  var sceneKey = Knack.scenes.getBySlug(currentScene.slug)?.get('key');
  if (sceneKey === 'scene_xx' && Knack.getUserAttributes()?.id) {
    window.location.href = '#member-articles';
  }

});

Whenever someone visits your Articles page, this code will check if that user is logged in, and if so, will redirect them to the Member Articles page immediately. If they aren’t logged in, they will remain on the Articles page.

You might also want to put a friendly link on the public Articles page which says something like: 'Already a member? Click here to login’, linking to the Member Articles page.

Hope that’s useful!

1 Like

This is perfect, thank you Stephen!

Maybe one more related question . . . I have a “log in” button in the top main menu that links to a login page. I want this hidden when the user is logged in, or I want to change its text (to the actual title of the login page). Any ideas?