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
Thanks
I plan to use all of these, I hope it's working as advertased :-)
Thanks for publishing this!
Taxonomy term
What about restricting it to a term?
</taxonomy/page/view/1>
</taxonomy/page/view/1>
--
Drupal services
My Drupal services
Restrict a block to a set of roles!
Update text as follows:
Doesn't Seem to work with Drupal 4.6.4
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:
What am I doing wrong? This is running an a Red Hat Enterprise 3 Server with Apache 2/PHP 4.3/MySQL 4.
global not $global
title says all
--
Tips for posting to the forums.
When your problem is solved, please post a follow-up to the thread you started.
Oops
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.
Never thought of that!
To think I was about to set about writing something to do this!
Cheers :-)