Block Permissions - Guest-Only Content

Permalink
Is there a way to create a block that only appears to guests? For example,

When a guest visits, they see a content block saying "please login to view this information".

When a user logs in, then, they instead see a user-only content block.

Is this possible? Thanks.

bballhermit
 
pixelfish replied on at Permalink Reply
pixelfish
yeah you can do this with advanced permissions. Its something you have to turn on. read the basic info about permissions athttp://www.concrete5.org/documentation/general-topics/simple-permis...
bballhermit replied on at Permalink Reply
bballhermit
Right, I already have advanced permissions enabled... I tried marking the "You need to login to view this content" block visible to only guests, and the actual login-required content visible to everyone except guests. However, the guest-only content is still viewable after login. Understand my question? Thank you.
Mnkras replied on at Permalink Reply
Mnkras
Currently, Concrete5 Treats all users as guests, no matter what group they are in, you can use an isLoggedin(); check in php in a custom block to add that functionality
bballhermit replied on at Permalink Reply
bballhermit
I installed the PHP block add-on. I am trying to add this functionality by putting the following code into a php block. I am new to php, and it is returning errors. Can you help?

Basically, if a visitor hits the current page and they are not logged in, they will still see the current page they are on. If a visitor hits the page and is logged in, I want it to redirect over to a new page.


<?php
if ( isLoggedin() == TRUE ) {
   echo header( 'Location:http://www.mysite.org/redirectedpage.html'... ) ;
}
?>
Rushing replied on at Permalink Reply
I just ran into this same thing, and here's the most straightforward fix, IMO. Create a custom template. For instance, create a "guest_only.php" file in blocks/content/templates with this:

<?php 
   defined('C5_EXECUTE') or die("Access Denied.");
   $content = $controller->getContent();
   $page = Page::getCurrentPage();
   $u = new User();
   if(!$u->isRegistered() || $page->isEditMode())){
      echo $content;
   }
?>



Similarly, you could use the condition above on a more complex block type and just include the original template where you see echo $content above.