Rosamunda
Rosamunda

Reputation: 14990

How to programatically print a user´s picture? This code won´t work

I’ve tried this so far in a Drupal 7 installation:

<?php print $user_picture; ?>
<?php print $user->picture ?>
<?php print $node->picture ?>

None of these snippets will get me the picture printed on the page.

I’m using Devel’s module, so I tried to get it to give me some hints. This is all I get:

picture (String, 1 characters ) 0
$...->picture

I’ve read that to print a variable you just print or echo it (echo $var1 for example). So why won’t this work? I’m adding this snippet inside my node.tpl.php template.

Any thoughts on this? Thank you for your insight!!

Update: This is the result of var_dump($user_picture):

string(0) "" 

Upvotes: 1

Views: 652

Answers (1)

Clive
Clive

Reputation: 36956

If all else fails:

global $user;
$image = theme('user_picture', array('account' => $user));
print $image;

Upvotes: 1

Related Questions