How does one display a custom field from a user's profile in comment.tpl.php?


The comment.tpl.php template file receive a $comment value, which contains the comment object. Between its properties, there is $comment->uid, which can be used to get the user object for the author of the comment, with user_load($comment->uid). If you are instead interested in the author of the node containing the comment, then you can use the following code.

$node = node_load($comment->nid);
$uid = $node->uid;
if ($uid) {
  $user = user_load($uid);

In both the cases, the code should be used in the preprocess function, not in the template file used for the comments. In this case, $variables['comment']->uid, and $variables['comment']->nid are instead used.

  • Thank you! I have just one question. How do i show term refference field? Thank you! – Dzoni Feb 4 '13 at 22:20
  • That is a different question. :) There is probably a question about that already. – kiamlaluno Feb 4 '13 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.