Hi there

I'm trying to pull and display elements from the users profile into a side block. I have zero PHP skills, so am guessing my way through, but here's exactly what I've put into the block, but nothing appears:

print $user->name

I guess I'm missing something v basic?

Many thanks in advance,

Neil.

Comments

venkat-rk’s picture

Please look at the excellent user profile snippets by Dublin Drupaller for possible solutions:
http://drupal.org/node/35728

Dublin Drupaller’s picture

Hi Neil,

It's not clear if it's the visitors profile details you want to put in a block or for example, if you are looking at someones blog, their profile info appears in a block.

Eitherway, I think the key to it would be the Profile_load_profile($account) function...

Click for an example of an "about me block" that onlyt appears when someone is looking at their blog.

hope that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

NeilMcEvoy’s picture

Hi Dub

Yeah, I'd like to display a synopsis of a user in a right block when one of their blogs is displayed. Their picture, few basic details, link to profile etc.

If the about me block example does this it is perfect, thank you very much! :-)

Stupid question: Can I just cut and paste from the example?

Many, many thanks,

Neil.

Dublin Drupaller’s picture

Hi Neil,

I haven't tested it, but you should be able to (I just edited it to correct a typo I spotted).

Follow these steps:

  1. Under ADMINISTER -> BLOCKS click on ADD BLOCK
  2. Paste the snippet into the test area provided
  3. Edit the profile fields to match the profile field names you have chosen. e.g. the snippet uses an $account->country field. for the users COUNTRY. make sure it matches your profile fields. I tend to name them with the profile prefix, so my profile field variable would read $account->profile_country
  4. As a tip, go to ADMINISTER -> SETTINGS -> PROFILES and check the profile field names so you're sure.
  5. before saving your custom block, make sure you remember to use the PHP FILTER

hope that helps

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

Dublin Drupaller’s picture

here's a simplified version of that block snippet...tested in Drupal 4.7. beta3 (it also should work with 4.6)

<?php
    if(arg(0)=='blog' & is_numeric(arg(1))){ // only show this block when someone is looking at a blog
    $accountid = arg(1); // get the user id of the blog you are looking at

    $user = user_load(array('uid' => $accountid));
    profile_load_profile($accountid); //load the profile for that user
/**
* the following lines check to see if a profile_field
* has been set and displays them if they have.
*
* Copy these lines and edit the profile_field names and
* their prefixes to match the profile_field names
* you have used under ADMINISTER ->SETTINGS -> PROFILES
*
* This works with Drupal 4.5, Drupal 4.6 and Drupal 4.7
*/

    if ($user->picture){print "<img src=\"$user->picture\">";}
    if ($user->name){print "<b>Name:</b><br>$user->name<br>";
    if ($user->profile_country){print "<b>Location:</b>$user->profile_country";}
   }
?>

that should be more intuitive to follow and to edit, or extend.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

NeilMcEvoy’s picture

Hi Dub

Many thanks for this help. Unfortunately I'm getting an error, so I must be have followed it wrong a wee bit. Here's the error:

Parse error: parse error, unexpected $ in /home/mcevoyn/public_html/sandbox/includes/common.inc(1857) : eval()'d code on line 11

And here's my code:

if(arg(0)=='blog' & is_numeric(arg(1))){
$accountid = arg(1);
$user = user_load(array('uid' => $accountid));
profile_load_profile($accountid);
if ($user->picture){print "<img src=\"$user->picture\">";}
if ($user->name){print "<b>Name:</b><br>$user->name<br>";
if ($user->profile_summary){print "<b>Profile:</b>$user->profile_summary";}
if ($user->profile_web_site){print "<b>Web site:</b>$user-profile_web_site";}
}

Have I done something wrong somewhere?

Thanks again,

Neil.

Dublin Drupaller’s picture

if(arg(0)=='blog' & is_numeric(arg(1))){
$accountid = arg(1);
$user = user_load(array('uid' => $accountid));
profile_load_profile($accountid);
if ($user->picture){print "<img src=\"$user->picture\">";}
if ($user->name){print "<b>Name:</b><br>$user->name<br>";}
if ($user->profile_summary){print "<b>Profile:</b>$user->profile_summary";}
if ($user->profile_web_site){print "<b>Web site:</b>$user-profile_web_site";}
}

you were missing a } in one of your lines.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

NeilMcEvoy’s picture

So I was. And it kinda stands out too!

However hasn't worked. No error now, but it just doesn't display anything, just a blank space.

Thanks, Neil.