Template item with viewing permission applied!

Permalink
Is there a way of placing content within a template page that has the permission level already set? i.e an image in the top right corner that is only viewable when you're logged in as a guest user!

benvickers
 
glockops replied on at Permalink Best Answer Reply
glockops
There are several ways of doing this, so here are two examples - insert this PHP code into your template where you need the image to display.

If you only care about users that are not logged in (i.e. Guests)
<?php if(!User::isLoggedIn()) { ?>
<!-- Display your content -->
<img src="http://placehold.it/100x100" />
<?php } ?>


If you want to display something when a user is a member of a certain group or groups
<?php
// Groups to display to (will display to any user in one of these groups)
$displayGroups = array("Editors","Cool People","Kittens");
$u = new User();
$g = $u->getUserGroups();
if(count(array_intersect($g,$displayGroups)) > 0) { ?>
<!-- Display your content -->
<?php } ?>


I also think there is an API call you can use, but I think it's based on a single user group.
glockops replied on at Permalink Reply
glockops
Also, I believe more granular block permissions are going to be included in the next release of concrete5.