By robhamm on
I need to show certain blocks to pre-authenticated users and authenticated users while hiding it from certain other roles.
The problem here is that everyone who registers automatically has the authorized user role, so there is no way to show a block to authenticated users while hiding it from other roles. This is not editable through Drupal's user interface.
Any ideas?
Comments
PHP code
Try the following code in your "Page specific visibility settings" for the block, using the "Show if the following PHP code returns TRUE" setting:
This should show if the user belongs to the 'authenticated user' role or the 'anonymous user' role and only one of those roles. Note that in my testing, the first user was affected, as it has the 'authenticated user' role and only that role, but not users that had either 2 or more roles.
(Username formerly my full name, Richard Eriksson.)
Thanks, man. I also found
Thanks, man. I also found another workaround. Since the blocks in question are ads that I don't want paid subscribers to see, I just set up a copy of Garland for which I set the blocks not to show, and made the paid subscriber role the only role that is able to switch themes. So when someone subscribes, they gain the new role and receive an email telling them how to change themes.
Your way, however, seems much better, as it is not theme-dependent. I'll try it out.
Rob Hamm
http://www.bluecrashkit.com (my current webcomic and means of support)
http://www.syberfang.com (my upcoming webcomic)
Nice Richard! This works
Nice Richard!
This works great, thanks so much!
-----------------------------------------------
The Future is Open!
Thanks Richard, your code
Thanks Richard, your code works fine.
But how would I have to change the code in order that the block won't show up for "anonymous users" & the custom "privileged users" role.
In other words, the block should only show up in role "authenticated users" and hide from all other roles.
Administer block settings.
Home » Administer » Site building » Blocks » Configure block.
In the "Role specific visibility settings" select "authenticated user" and save.
This does not work because
This does not work because it will show to "privileged users". ;)
Any further updates on this
Any further updates on this topics please?
I am struggling with this.
This works for me...
Hi
This is something strange in Drupal because conditions and roles are somehow mixed. However with this PHP code in the blocks visibility settings you can expose the block to anonymous and/or authenticated users but not to any higher role.
If you would like to show the block only to authenticated users, remove the second condition. If you would like to show the block only to anonymous users remove the first condition.
Hopefully this helps
Regards
Tilo
show blocks to authenticated users while hiding from other roles
Thank you for this code which was posted early 2011. I've tried this in Drupal 7, (that is show a block to only anonymous and authenticated users and no other role) but does not seem to work.
Has something perhaps changed in D7? Most appreciate any help :)
The simplest code I have
The simplest code I have found for showing a block to only anonymous or authenticated users with no other role is:
Use "Hide Block by Role"
Use "Hide Block by Role" module
http://drupal.org/project/hide_block_by_role