Hi folks,
I disabled core user pictures in favor of an imagafield in a content profile. I'd like to place a small user picture thumb on every page, so the current user can easily access his own profile (with a click on his avatar).
I got it working, but I fear that the following approach could be bad for performance. Furthermore, isn't it the good drupal way to leave logic out of the template and use only print statement in templates.
So this is my code:
<?php
$avatar = $content_profile->get_variable('profile', 'field_profile_avatar');
$title = $content_profile->get_variable('profile', 'title');
print theme('imagecache', 'user-thumb-small', $avatar[0]['filepath'], $title, $title);
?>
How can I do it the Drupal way? I surely want to get these variable initialisation out of the template file. I tried to put it in template.php, but this did not work, as I am not that exprienced with this ($content_profle->get_variable() ) is not available in template.php, is it?
thanks.
Comments
Comment #1
igorik CreditAttribution: igorik commentedHi
Why do you think it is not a drupal way? I think it is right.
You test and print avatar image in user-picture.tpl.php where it is correct.
My content profile code for user avatar is this, it is a little bit complicated, because I am doing user avatar
from 1. his imagefield image for avatar, 2. from his imagefield profil image 3. default image based on user sex (cck field 'pohlavie')
Igor
http://www.somvprahe.sk
Comment #2
pheraph CreditAttribution: pheraph commentedI have a very similar question, but I cannot use the .tpl.php-method, because I have to override the function phptemplate_activity_user_picture($account) from the activity-module in the template.php. As the TS stated the $content_profle->get_variable()-function is not available in the template.php.
Basically the code looks like this, but the last line throws an error. :-(
How can I achieve that in the template.php?
Regards,
jakewalk