tags:

views:

820

answers:

2

I'm trying to get the avatar (profile picture) located in the $profile array to appear in a BLOCK. The variable $profile is not accessible from blocks. It's scope is only in that actual user-profile.tpl.php file. So... does anybody know how I can execute something like this:

print $profile[user_picture];

in a drupal BLOCK?

A: 

You can try using the following code in a new block (admin/build/block/add):

<?php
global $user;
$output = theme_image($user->picture, $alt = 'user pic', $title = 'user pic');
print $output;

This gives you access to the global $user variable and then you can use the picture property to get the URL for the current users profile picture.

quickcel
Yes, but that's not the picture I want. If I'm viewing somebody else's profile, i want to be able to see that person's picture. I solved it by creating a block view.
RD
gotcha - thanks for the udpate
quickcel
+1  A: 

I figured i might as well post it here as well. See my second comment on the first thread in this discussion. Below is my code I used with INSERT VIEW to get what I wanted:

<?php 
       $profileUser = "";
       if (arg(0) == "user") {
            $profileUser = arg(1);
       }
       // removed some other checks i do to populate $profileUser
?>

[view:VIEWED_PROFILE_AVATAR=block=<?php print $profileUser; ?>]

I hope that helps someone.

RD

related questions