Hi

Probably an easy programming question to those who can, but if you can't...

I'm using Views and Contemplate to show teasers and hide the body if the user doesn't have the correct role membership (e.g. the "agenda" role in this example):

global $user;
if (in_array('agenda', $user->roles)) {
print $body;
}

How should this be adapted so that, instead of simply hiding the body, an unauthorised user is redirected to a standard 403 page (i.e. "join now to read this article").

Kind regards,

Ali

Comments

jrglasgow’s picture

you could do the following using the drupal_access_denied function:

global $user;
if (in_array('agenda', $user->roles)) {
  print $body;
}
else {
  drupal_access_denied();
}

once the drupal_access_denied function is called the Drupal 403 error page is shown

AliMartin’s picture

Thanks jrglasgow - worked a treat :o)

jrglasgow’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.