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)))),
    );
  }
}
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论