render()
only returns the string, it doesn't print it to the output. This code should work:
<?php print render(user_view($account)); ?>
Assuming of course that you have loaded the $account
object. If not you probably want to use something like:
global $user;
$account = user_load($user->uid);
As an aside, using the PHP filter is considered bad practice (it uses eval()
which is an inherent security risk).
The best way to get what you're looking for is to write a small custom module that implements hook_block_info()
and hook_block_view()
:
function MYMODULE_block_info() {
return array(
'user_profile' => array(
'info' => 'User Profile Block',
'cache' => DRUPAL_NO_CACHE
)
);
}
function MYMODULE_block_view($delta = '') {
$block = array();
if ($delta == 'user_profile') {
global $user;
$account = user_load($user->uid);
$block['subject'] = 'User Profile';
$block['content'] = user_view($account);
}
return $block;
}
If your new to writing modules the best resource I know of is the Module developer's guide, and in particular the Creating Drupal 7.x modules sub-section; it will walk you through all of the steps necessary to get your module up and running.
UPDATE
Just to address your second comment...
I think the easiest way to get only certain fields to display would be to install the Entity View Modes module. Then you can create a custom view mode for the user entity (called block_profile
or something), and in the "Manage Fields" admin page for users assign only the fields you want to be displayed to that new view mode.
Then you can pass the new view mode to the user_view()
function:
$block['content'] = user_view($account, 'block_profile');
And voila, your block will contain only the fields that you've added to the new view mode through the admin UI.
If Entity View Modes is causing you issues you can just uninstall it, and add the new view mode yourself using hook_entity_info_alter()
(again in your new custom module):
function MYMODULE_entity_info_alter(&$info) {
$info['user']['view modes']['profile_block'] = array(
'label' => t('Profile Block'),
'custom settings' => TRUE
);
}