Show different panels to logged in and anonymous users

Events happening in the community are now at Drupal community events on www.drupal.org.
Gerard McGarry's picture

I'm struggling with creating a panel layout for my site homepage.

What I want to do is display different content depending on whether the user is logged in or anonymous. The logged in user will see recent content, plus a small control panel to help them get started publishing blog entries, etc. The anonymous user will see an invitation to join the community, plus some recent content blocks underneath in case they want to browse the site.

I've searched for an answer, but there doesn't seem to be a way to load a panel conditionally based on whether the user is logged on or not. I assume that this can be achieved in at least two ways:

  1. By having two seperate panel pages and some kind of logic to select the right one depending on the user's status. Or,
  2. Is it possible you can make a panel pane visible to anonymous/authenticated users in the same way you can for blocks?

I'd really appreciate it if someone in the community could push me a little further along the path toward solving this one! It's a real head-scratcher for me!

Comments

The answer? Variants and Selection Rules

Gerard McGarry's picture

Right, I've actually come up with an answer to this one by myself (always happens when I write out the problem!)

I created a panel page with a stacked, two-column layout. Into this, I added the invitation to join in the top pane, then various 'latest content' lists in the parts below. I saved this layout, then cloned it to create a second variant.

Since the second variant was intended for logged in users, I removed the invitation to join and left it with just the 'latest content' columns. So, that being done, I had the two homepage variants in place. Now to set the permissions...

The original variant of the homepage was intended for anonymous users - I went to the selection rules for the variant and set it to display based on User Role, then selected Anonymous user. I went to the second variant and set it to display for Authenticated users. Then, before I formally set it as the homepage, I did some testing to make sure the page worked correctly both as a logged in user and as an anonymous user.

So, there you go. If there's a better way to do this, please let me know, but I hope that this write-up helps somebody else who might be having the same problem.

Thanks Gerard - that helped a

guysaban's picture

Thanks Gerard - that helped a lot.

Thanks a lot

shekhar_mittal's picture

I needed this badly.

Thanks!

fax8's picture

Thanks for sharing this one. Works perfectly.

www.varesano.net - Fabio Varesano Personal Homepage

Drupal 7 logic

jwilson3's picture

With the latest versions of Panels 3 on Drupal 7, the logic in the Selection Rule needed to be slightly different to get this to work for me.

Namely, the homepage for authenticated users had to use the same "anonymous user" role and negate it using the "Reversed (NOT)" checkbox.

Variant 1: Visitor Homepage
Selection Rules: User role => Logged in user has role "anonymous user"

Variant 2: Member Homepage
Selection Rules: User role => NOT (Logged in user has role "anonymous user")

Panels

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: