User Property Custom Display
| Custom displayer for User properties |
| Type | Snippet |
| Category | |
| Developed by | |
| Rating | |
| License | GNU Lesser General Public License 2.1 |
Table of contents
Description
Since XWiki 4.3 (), the core displays a List of Users property with the avatar and the name of each user in view mode, and with a user picker in edit mode, so you don't need this snippet to get a nicer display. It remains an example of a custom display that changes how a property is viewed, here showing only the avatars of the users, while it uses the core displayer for the other modes.
Edit your List of Users property using the Class Editor and in the Custom Display field, type:
{{velocity}}
#if ($type == 'view')
{{html clean="false"}}
#foreach ($user in $value.split('\s*,\s*'))
#if ($user != '')
#set ($userReference = $services.model.resolveDocument($user, 'user/current'))
#getUserAvatarURL($userReference $avatar 40)
<a href="$escapetool.xml($xwiki.getURL($userReference))"><img src="$escapetool.xml($avatar.url)" alt="$escapetool.xml($xwiki.getPlainUserName($userReference))" height="40"/></a>
#end
#end
{{/html}}
#else
## The other display modes (edit, search, hidden...) use the core displayer of the List of Users property.
{{html clean="false"}}
#template('displayer_users.vm')
{{/html}}
#end
{{/velocity}}The script escapes every value it writes into HTML with $escapetool.xml, so that a user reference containing quotes or HTML can't break the page or inject markup. If you write wiki syntax instead, escape the values with $services.rendering.escape, and see the escaping of link labels for the values inside the label of a link.
Example
When you view your page you'll see for example:

And if you use a Live Data or a Livetable with a column displaying the List of Users property you'll get:
