I'm trying to control a blocks visability based on a field in a custom profile.

There is an example in the hand book http://drupal.org/node/64330

But it doesn't seem to work.

Has anyone else managed to get this working in v5.1 ?

Here is my code..

  <?php
      global $user;
       if ($user->profile_membertype == Gallery){
       return TRUE;
       } else {
       return FALSE;
       }
   ?>

Comments

tostinni’s picture

I think you're missing some quotes around "Gallery"

      global $user;
       if ($user->profile_membertype == 'Gallery'){
       return TRUE;
       } else {
       return FALSE;
       }
   
nigels’s picture

Thanks for the help,

But still doesn't work.

Do you think there is some difference with drupal v5.1 ?

Cheers

nigels’s picture

Im having real trouble trying to control block visability according to the content of a Profile Category Field on Drupal v5.1

<?php
      global $user;
       if ($user->profile_membertype == "Gallery"){
       return TRUE;
       } else {
       return FALSE;
       }
   ?>

Anyone any ideas?
or maybe there is another way to do this?

tostinni’s picture

Ok, I don't know how is this was working on 4.7, but testing in 5.1 you have to load profile first so you have:

  global $user;
  profile_load_profile($user);
  if ($user->profile_membertype == "Gallery"){
    return TRUE;}
  else {
    return FALSE;}
   

Of course you should add a check for the availability of profile module like if (module_exists('profile')) { ... }

nigels’s picture

It works perfectly with that extra bit!

Thanks a million for your help Tostinni!