I want to hide navigation for anon users but it should be visible for auth users (user/1 -> I've only one registered user). I am using 4.7 beta 6. I read some patch updates, but they don't seem to be for the version that I'm using. Can some one please let me know, if what I want is possible and how?

Thank you very much,
Joseph

Comments

bjornarneson’s picture

cmsproducer’s picture

The simple approach that works for me is to move all the menu items that would display to anon-users under a menu item that is already restricted to logged in people... Once there are no menu items for anonymous users, the Navigation disappears when you logout. I have done that on my website and I have a direct link to Account login. Once you login, Navigation re-appears showing onnly those items that you are allowed to see in 'Access Control'

Checkout my setup.
I think it works just fine without tinkering with Drupal code (not that I am afraid, but I choose my battles and if I can find a simple walk-around, why re-engineer the plumbing)?

-----
Web Development, Production & Marketing Advice - http://www.cmsproducer.com/click/26/3

jjude’s picture

subject says it all. Thanks

tredgettdm’s picture

Please forgive my ignorance, but how do you restrict access to logged in users for menu items ?

I cannot find this documented.

Many thanks

Dave T

cmsproducer’s picture

You are right to point out that there is no explicit way to select visibility of menu items, hence the walk-around. Based on Access Control (under admin), if a feature is allowed for anonymous users, then it's menu items will be visible.

If you want to control the visibility of menu items that you have created yourself (that are not controlled by access-control), then I would suggest using the approach outlined in http://drupal.org/node/50413

-----
iDonny - Web CMS Development, Design, and Web Marketing Advice

tredgettdm’s picture

Thanks for the prompt repsonse....

If I interpret your reply correctly, in access control, you would deny "Node module->Access Content", to anonymous users by un-checking the box. Consequently any menu item of type "content" would not be visable to anonymous users.

Is this correct ? or can you give a specific example.

Thanks

Dave T

cmsproducer’s picture

Sorry for not answering your question in good time... I do not get to read the progress on all my contributions every day (You can get faster responses on Drupal and Web production support here).

You can edit your template an insert PHP code to only show certain sections to logged-in users or users of a certain kind.
For Blocks, first identify the block ID of the blockt hat you want to hide,
Edit the block.tpl.php file and enclose the whole code in a conditional that will only show it if the user is logged in (for the particular block ID) Here is an example:

global $user; if ($block-id == xx)&&($user->uid != 0) {
Comment- If the current block is the exclusive block, and the user is logged in, then show it
}




Then




global $user; if ($block-id != xx) {
Comment- If the current block is NOT the exclusive block then show it
}

Where XX is the block ID of the block whose apearance you want to control
There is a handbook page describing how to control block display... and all you have to do is make the user status the determining condition for the block in question

-----
iDonny - Web CMS Development, Design, and Web Marketing Advice

dbotton’s picture

One way to hide menu items from users is to create another menu with the items you wish to hide. Then turn the block on for that menu and set the conditions of the block displaying using php like the following that shows the block only for signed in users:

<?
   global $user;

   if ($user->uid > 0) { return true; } else { return false; }
?>
sumoanand’s picture

This is the best way for me

Thanks,
Sumeet Anand

smilne’s picture

I have a role for some users which is simply 'forum member'. they can't do anything but post to the forum, so i don't need them to see the navigation block (but it should still appear for users with other roles, e.g. content provider, admin etc).

How can I hide navigation from users who belong to this specific role?

EDIT:

Solution was to configure the navigation block to show under the following condition:

if (!is_array($user->roles) || !in_array('forum member', $user->roles)) {
    return TRUE;
}else {return FALSE;}

As I understand it (from the article where I found the code) this will hide the block from all users who belong to 'forum member' EVEN IF they belong to other roles too. This code is sufficient for me as I don't use multiple roles, but if I wanted to do this I would need a way of asking whether a user was a member of 'forum member' and nothing else. Any thoughts?

With Thanks.