How to modify the user profile display?

Last modified by Vincent Massol on 2017/11/04

If you wish to simply add new fields to the user profile, you can do so using the User Profile section in the Administration.

However if you need to change the way user profiles are displayed or how they behave then you'll need to modify some wiki pages that are provided by default and that contain the logic to display user profiles.

For example, imagine you may want that only administrators be able to view some information from the user profile.

First thing to know is that the page used to display user profiles is the XWiki.XWikiUserSheet page (you can find out how to navigate to it).

This page display the vertical menu on the User Profile and in turn uses several other pages to display the content of each tab. For example: XWiki.XWikiUserProfileSheet to display profile information (the "Profile" tab). 

So imagine for example we want to display the user profile page but hide the values of the various profile fields if the user is not an administrator. To do that edit XWiki.XWikiUserProfileSheet and find the line that contains $doc.display():

<dd #if("$!vCardProperty" != '' && !$inEditMode)class="$vCardProperty"#{end}>$doc.display($sectionProperty)</dd>

And replace it with:

#if ($hasAdmin)
 <dd #if("$!vCardProperty" != '' && !$inEditMode)class="$vCardProperty"#{end}>$doc.display($sectionProperty)</dd>
 <dd #if("$!vCardProperty" != '' && !$inEditMode)class="$vCardProperty"#{end}>//For admins only//</dd>

Important note: Modifying default wiki pages means that when you're going to next upgrade XWiki there might be some conflicts raised by the Distribution Wizard (DW) since you'd have made changes to the page and the XWiki development team may also have made changes. The DW will try to merge the changes but if it cannot it'll ask you to choose which version to use.


Get Connected