MyBB Community Forums

Full Version: Avatar Variable on Homepage
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What variable should I use if I want to get the user's avatar and display it on the homepage?
Nevermind, answered my own question. Seems to be $mybb->user['avatar']

You guys should document your variables a bit better... or do you, and I just missed the documentation?
Not really a full "variable" guide. But the general structure is documented here. [wiki]Authoring_Templates_and_Themes#Variables[/wiki]
The problem is that some variables only work on certain pages. If you want to find a certain variable just ask and we can help you find one.
Okay, thanks for the help Smile
Ok, $mybb->user['avatar'] gets the URL of the avatar image and we can use it inside a <img> HTML tag, but..... What if the user don't have an avatar? and I still don't want to use default avatar system??

It would be nice using a variable like postbit templete does, wich doesn't prints out anything if the user doesn't have an avatar.

Please reply. =)
Put it in index.php

if($mybb->user['avatar'])
{
     $mybb->user['avatar'] = "<img src=\"{$mybb->user['avatar']}\" alt=\"{$mybb->user['username']}\" />";
}
Wow! thank you for your quick reply. Just a little detail:

I'm trying to show user's avatar in the welcome box. I've installed "Side Boxes" plugin so I can show Welcome box in my forum homepage, and the changes I make in "portal_welcome_membertext" template are reflected in my homepage, so question is: Do I need to add that PHP code in the template? If so, how is this possible?.. I've tried adding <?php and ?> tags so the code can be recognized as valid PHP code, but it is still being parsed as (kind of plain) text.

Remember, user's avatars are showing fine, but if a user doesn't have an avatar, it shows the "X" browser image meaning "not found image".

Would you guys reply me again?

EDIT: Lex, I understand your suggestion, but that code mod is dangerous because there are possibilities that other plugin or code mods uses $mybb->user['avatar'] to get ONLY the URL string, not the whole html image tag.