Skip to content

Instantly share code, notes, and snippets.

@sachbearbeiter
Created April 3, 2014 15:02
Show Gist options
  • Save sachbearbeiter/9956012 to your computer and use it in GitHub Desktop.
Save sachbearbeiter/9956012 to your computer and use it in GitHub Desktop.
D7: Comments: Get access via foo_preprocess_comment(&$variables) to the comment authors profile image from an ($user) imagefield and print it into the comment.tpl.php template.
<? if (!empty($image)) : ?>
<img src="<?= image_style_url('mini',$image); ?>" alt="Profile image" />
<?php endif; ?>
/**
* Preprocess comment
*/
function foo_preprocess_comment(&$variables)
{
$comment = $variables['comment'];
$userID = $comment->uid;
if ($userID != '0') {
$user = user_load($userID);
$profileImage = field_get_items('user', $user, 'field_user_image');
if ($profileImage) {
$variables['image'] = $profileImage[0]['uri'];
} else {
$variables['image'] = '';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment