Log in

View Full Version : Avatar in header template


Fraik
07-17-2008, 05:12 PM
I am trying to show the user's current avatar in the forum header (version 3.7). I used this code in my vB 3.6 setup, which displays the users' current avatar, or the default avatar if they do not have one or aren't logged in.

<if condition="$vbulletin->userinfo['avatarid']">
<img src="$bbuserinfo[avatarpath]" alt="$bbuserinfo[username]'s Avatar" border="0" width="64" height="64" />
<else />
<if condition="$vbulletin->userinfo['hascustomavatar']">
<if condition="$vbulletin->options['usefileavatar']">
<a href="profile.php?do=editavatar"><img src="$vboptions[avatarurl]/avatar$bbuserinfo[userid]_$bbuserinfo[avatarrevision].gif" title="$bbuserinfo[username]'s Avatar" alt="Avatar" border="0" width="64" height="64" /></a>
<else />
<a href="profile.php?do=editavatar"><img src="image.php?u=$bbuserinfo[userid]&amp;dateline=$avatar[dateline]" title="$bbuserinfo[username]'s Avatar" alt="Avatar" border="0" width="64" height="64" /></a>
</if>
<else />
<a href="profile.php?do=editavatar"><img src="$stylevar[imgdir_misc]/noavatar.gif" alt="guestavatar.gif" title="No Avatar Specified" border="0" width="64" height="64" /></a>
</if>
</if>

The above code works in determining if someone has a custom avatar or not, but does not return the img src for the avatar - while it did in vB 3.6

Any help on fetching the users current avatar in the header template?

Thanks,
Freek

Dismounted
07-18-2008, 07:21 AM
You'll find a clue in class_core.php (vB_Session constructor).

With your code, you would've needed a plugin to fetch the data - the data isn't there by default.

Fraik
07-18-2008, 01:19 PM
Ah

My code works a 100% with this line added in the config.php file:
define('AVATAR_ON_NAVBAR', 1);

:D

Dismounted
07-19-2008, 04:21 AM
See, a bit of searching and you get a solution ;). Also, you don't have to have that code in config.php - you can have it in a plugin at init_startup. Furthermore, consider using the function fetch_avatar_from_userinfo, rather than putting all the logic in your templates.