当他登录时,是否有Drupal模块在块中显示用户名?
感谢
答案 0 :(得分:4)
块体:
<?
global $user;
print $user->name;
?>
答案 1 :(得分:3)
在Drupal 7中,使用名为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)))),
);
}
}