开发者

Drupal: I need to display the user name in a block

Is there a Drup开发者_开发知识库al module to display the user name in a block, when he is logged in ?

thanks


  • Creat a new block.
  • Format: PHP code

Block Body:

<? 
global $user;
print $user->name;
?>


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)))),
    );
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜