Display block according to Profile Category Field

Last modified: May 18, 2006 - 20:02

This is a useful tool for displaying a block based on the field value of any profile category. Example usage would be to display a block to all users from any particular country.

First it is necessary to create some profile categories using the profile module. It is expected that you have experience on how to do this. More info can be found here http://drupal.org/handbook/modules/profile .

Create a new block and insert your php code, static content or use the views module to create a customised extraction of data.

Save the block. Click on administer -> blocks -> configure next to the name of your newly created block. At the bottom of the config page, copy and paste the following code after you adjust it to suit your profile_field and field value. Make sure you select Show if the following PHP code returns TRUE (PHP-mode, experts only).

<?php
global $user;
if (
$user->profile_usercountry == South Africa){
  return
TRUE;
} else {
  return
FALSE;
}
?>

Save configuration and enable the block. It should display to all users who are from South Africa. Useful tool for marketing and country specific communication. I used this method to create a drop down list on the registration page, asking new users to select a type of account.

More information about block visibility here...
http://drupal.org/node/64135

 
 

Drupal is a registered trademark of Dries Buytaert.