Page 1 of 1

Current Logged In User's Username and Avatar

Posted: Wed Apr 21, 2010 9:58 pm
by GoremanX
I'm trying to find the variable that will give me the current logged in user's username. I assumed it would be {USERNAME}, but that returns nothing. I tried {L_USERNAME}, but that just returns the English word for Username (which is, unsurprisingly, Username}. I tried {U_USERNAME}, but I get nothing from that.

I'd also like to know what variable will give me a url to the current logged in user's avatar.

Thanks,

Re: Current Logged In User's Username and Avatar

Posted: Wed Apr 21, 2010 10:12 pm
by 3Di
the function get_user_avatar takes care (you bet?) of the user's avatar. (includes/functions_display.php)

the function get_username_string takes care of the user's name. (includes/functions_content.php)

hope this helps

Re: Current Logged In User's Username and Avatar

Posted: Wed Apr 21, 2010 10:42 pm
by GoremanX
But those require that I supply a specific user ID. Surely there must be some simpler way of displaying the current user's name on the page. It's only for a dead-simple "Hi, {USERNAME}" thing with their avatar next to it....

Re: Current Logged In User's Username and Avatar

Posted: Wed Apr 21, 2010 11:05 pm
by 3Di
1 - $user->data['username'] gives you the user name

2 - $user->data['user_avatar'] gives you the phpbb location/filename of the user's avatar image

depending on where you are bound to use these you maybe need to use also:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
$user->session_begin();

Re: Current Logged In User's Username and Avatar

Posted: Wed Apr 21, 2010 11:58 pm
by GoremanX
ah hah! That worked well. I added this to the php file of the login mod I'm using:

Code: Select all

$template->assign_var('CURRENT_USERNAME', $user->data['username']);
and now adding {CURRENT_USERNAME} within that mod makes the current logged-in user's username appear.

Thanks!