Community Documentation

Display block according to Profile Category Field

Last updated May 18, 2006. Created by Mojah on May 18, 2006.
Log in to edit this page.

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

Comments

This no longer works with

This no longer works with Drupal 5.x and 6.x.

I got it to work on Drupal 6.x using the information on this comment:

http://drupal.org/node/127730#comment-211928

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.
nobody click here