Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By forestgardener on
Hello
I am not using the built-in Enable user pictures in Drupal 7 account settings - for reasons to do with displaying messages. Instead I have created a new user defined field field_user_picture for users to upload their pictures.
I would now like to display this field together with any comments that a user makes. However I can not find how to make this variable appear in comment.tpl.php.
Any help would be greatly appreciated.
Thank you in advance
Craig
Comments
=-=
utilize the devel module to look into what's available.
In comment.tpl.php, try
In comment.tpl.php, try printing $content array, in that array you can find the image field (field_user_picture).
Hi,Please have a look at
Hi,
Please have a look at template_preprocess_comment(&$variables) function. You can override this in your themes template.php by implementing YOUR_THEME_NAME_preprocess_comment(&$variables). Where you can override picture variable, see example below:
Yogesh
http://yogeshchaugule.com/blog
Used tokens
Hi Yogesh
Thank you for your help and thank you to VM and Usha too.
In the end I took advantage of the token filter module and used the following code in comment.tpl.php (I know I should move it over to template.php - but that can wait for another day).
<?php
if (token_replace('[comment:author:field-user-picture:file]', array('comment' => $comment)) !='[comment:author:field-user-picture:file]'){
$comment_author_pic_file = token_replace('[comment:author:field-user-picture:file]', array('comment' => $comment));
} else {
$comment_author_pic_file = "default.png";
}
$comment_author_name = decode_entities(token_replace('[comment:author:name]', array('comment' => $comment)));
$alt_tag = $comment_author_name . "'s picture";
$title_tag = $comment_author_name . "'s picture";
$user_base_url = "public://user-media/user-pictures/";
$user_picture_url = $user_base_url . $comment_author_pic_file;
$picture = theme('image_style', array('style_name' => 'thumbnail_small', 'path' => $user_picture_url, 'alt' => $alt_tag, 'title' => $title_tag, 'attributes' =>array()));
Best wishes
Craig