In my current Confluence wiki project, I need to show the profile picture for the current user in the header of every page. This will help in a couple of ways:
- It gives the wiki a more human touch
- The wiki will be used in an environment where many of the people will be sharing computers, the user photo will allow them to quickly see who they are currently logged on as
I’ve googled and googled on this one, and I can’t find any current macros to do it. Bubbles, the community and social network plugin from Adaptavist, will have a macro for exactly this, but is currently in a closed beta… and I don’t need any other Bubbles functionality for this project.
After a bit of wrestling with the Confluence technical documentation and my first very basic Velocity markup language efforts, I’ve got something working, note that this will only work on pages (i.e. not in settings pages, etc). Copy and paste the code below into a new User Macro (Confluence > Administration Console > User Macros > Create a user macro) :
#set( $profile_pic = $userAccessor.getUserProfilePicture( $req.userPrincipal.name ) )
#set( $pic_src = $profile_pic.getDownloadPath() )
<a href="/users/editmyprofilepicture.action" title="Upload a different profile picture"><img src="$pic_src" alt="Your profile picture" border="0" /></a>
The macro code above links the profile picture directly to a page where the user can upload or change their user profile picture. If you don’t want the picture to be linked, use the code below instead:
#set( $profile_pic = $userAccessor.getUserProfilePicture( $req.userPrincipal.name ) )
#set( $pic_src = $profile_pic.getDownloadPath() )
<img src="$pic_src" alt="Your profile picture" />
Put “user_profile_pic” in the Macro name field, then untick “Macro has a body”, and set the drop down to “Macro generates HTML markup”. You can then include the macro in your Confluence page, or Adaptavist Theme Builder panel, with the macro code below:
{user_profile_pic}
Next task: make this into an easily distributable plugin that people can simply upload into their Confluence installation.
Simon,
I got this to work:
—————————————————-
You are: {report-image:global:current user > user:picture} {report-info:global:current user > full name}
—————————————————-
Now what I’d like to know is how to display the picture of a specific user on a page. Any thoughts there?
Thom
Hi Thom, thanks for the comment. Looking at the documentation, there’s an example of :
{report-image:content:creator > user:picture}
and the recipe for Contact Cards shows the macro being used within another context. I’d suggest asking the question in the comments over there; David Petersen, one of the main guys at Customware, is always very helpful.
You are a life saver. I have been trying to get the profile picture displayed in a business card layout for our dashboard for a month. Adaptavist and Atlassian documentation have been no help. Thank you! Thank you! THANK YOU!
Hi Liz, thanks for dropping by and I’m glad this was helpful! If you’re using this, or any other recipe, to display the user profile picture in multiple situations, beware – all the methods I’ve tried fail in one place or another, so be sure you’ve checked everywhere. If you’re just using it in one location, like a standard Confluence page, then it’s not a worry.
Hey Simon,
I know it’s been a while since you added this entry but I just tried your macro and it’s not working. =( It says “Your profile picture” within a box that has an ‘X’ in it. The link works but the actual picture doesn’t show. I’m running Confluence 2.8 and using Theme Builder 3.2.1. I’m trying to use the macro within the title panel. Can you help?
Nice job with this share some great info will come real usefull.
Hi,
The macro didn’t work for me too with Confluence 2.8.0
My concern is a little bit different, because i wan’t to get profile picture of any user : so i add a parameter. Note that $req.userPrincipal.name is not working anymore (but why ??)
#set($profile_pic=$userAccessor.getUserProfilePicture($param0))
#set($pic_src=$profile_pic.getDownloadPath())
#set($baseurl=$action.getGlobalSettings().getBaseUrl())
Jean.
Thanks. Works fine for me in 3.1
If you want to show the pic of a certain user e.g. for a static team gallery you can use:
{user_profile_pic:username}
with the changed code:
#set( $profile_pic = $userAccessor.getUserProfilePicture( $param0 ) )
#set( $pic_src = $profile_pic.getDownloadPath() )
Gute Seite, diese hat mir sehr überrascht.
Simon,
Thanks for sharing this. I’m using 3.4 and I needed to add the complete path to get it to work:
#set($baseurl=$action.getGlobalSettings().getBaseUrl())
#set( $profile_pic = $userAccessor.getUserProfilePicture( $req.userPrincipal.name ) )
#set( $pic_src = $baseurl + $profile_pic.getDownloadPath() )