Reputation: 64844
Is there a Drupal module to display the user name in a block, when he is logged in ?
thanks
Upvotes: 3
Views: 5181
Reputation: 1266
In Drupal 7, using a custom module named YOURMODULE:
/**
* Implements hook_block_info().
*/
function YOURMODULE_block_info() {
return array(
'YOURMODULE_logged_in_as' => array(
'info' => t('Login information ("Logged in as...").'),
'cache' => DRUPAL_CACHE_PER_USER,
),
);
}
/**
* Implements hook_block_view().
*/
function YOURMODULE_block_view($delta = '') {
if ($delta == 'YOURMODULE_logged_in_as') {
global $user;
return array(
'subject' => NULL,
'content' => t('Logged in as !name', array('!name' => theme('username', array('account' => $user)))),
);
}
}
Upvotes: 3
Reputation: 24630
Block Body:
<?
global $user;
print $user->name;
?>
Upvotes: 4