1

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?

apaderno
  • 28,547
  • 16
  • 75
  • 90
rockstardev
  • 13,479
  • 39
  • 164
  • 296
  • So far I can only imagine it has something to do with these: http://api.lullabot.com/file/core/modules/profile/profile-block.tpl.php and these: http://api.drupal.org/api/function/template_preprocess_profile_block/7 – rockstardev Aug 05 '09 at 15:23
  • You mention below that you found the answer by creating a view block - any chance of sharing the technique? – Bevan Aug 06 '09 at 09:51
  • Yay. First time I get to help someone! :-) Basically, I wanted that if you click on user X's profile, that it shows his name in a block. To do this, I created a view that displays a user's name. I then let this view take in a the uid as an argument and voila. I eventually extended it a bit using a module called "insert view" so that I can do some funky PHP commands. Let me know if I must give more instructions. – rockstardev Aug 06 '09 at 21:03

2 Answers2

2

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.

rockstardev
  • 13,479
  • 39
  • 164
  • 296
1

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
  • 506
  • 2
  • 8
  • 15
  • 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. – rockstardev Aug 06 '09 at 05:01