As a newbie to drupal, I found this info in various places on the forum, but here's a quick reference on how-to-do-it, rather than a philosophical discussion :)

RESTRICT A BLOCK TO ONLY THE FRONT PAGE

create the block as a PHP block with the following code:

if ($_GET["q"] == variable_get("site_frontpage", "node")) {
  return t("this block only appears on the front page");
}

RESTRICT A BLOCK TO ONLY A PARTICULAR ROLE

print_r($user) is a handy command to use if you want to see all the attributes besides role that you can use here.

Create the block as a PHP block with the following code:

global $user;

$role = $user->role;

if ($role == "full administrators") {
  return t("This content will appear to members of role: $role");
}

RESTRICT A BLOCK TO A PARTICULAR PAGE

Surf to the page, note the contents after the q= line

Create the block and save it

In the path for the block on the main block page, enter the path noted above with a leading slash.

For example, the news page would be: </import>

node 9 would be: </node/view/9>

You can use a regular expression here if you would like.






These all work fine in my 4.2 portal without clean URL's. Comments appreciated.

Comments

Gabriel R.’s picture

I plan to use all of these, I hope it's working as advertased :-)

Thanks for publishing this!

tommi-1’s picture

What about restricting it to a term?

killes@www.drop.org’s picture

</taxonomy/page/view/1>

mikegull’s picture

Update text as follows:

global $user;

$roles = $user->roles;
$approved_roles = array('admins', 'site editors', 'guest editors');
if (count(array_intersect($roles, $approved_roles)) > 0) {
  return '<a href="/admin">Admin Menu</a>';
}
wslntheline’s picture

This looks exactly like to sort of thing I am looking to put on my college radio station website (http://wsln.owu.edu). I am constructing a mass-email system using Simplenews, and I want to make a block that will show different links relating to mass emails depeding on user roles. I have posted the code I am using at http://wsln.owu.edu/errors/blockcode.txt, since I can't post it here. I am getting the message below:

Parse error: parse error in /home/wsln_987/public_html/drupal/includes/common.inc(1816) : eval()'d code on line 2

What am I doing wrong? This is running an a Red Hat Enterprise 3 Server with Apache 2/PHP 4.3/MySQL 4.

heine’s picture

title says all
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.

wslntheline’s picture

Shudda seen that. Thanks. I'm no longer using the module I was using the block with, so I can't see if this fixes the problem, but I bet that was it.

jondoesdrupal’s picture

To think I was about to set about writing something to do this!

Cheers :-)