{xuser:field}

Description

Inserts information about the currently logged-in user, taken from AA session state (apc_state xuser / xuid). With no argument it returns the login name; the special argument id returns the user item long ID; any other argument is treated as a field id or alias and returns that field from the user item. Returns an empty string when nobody is logged in, which makes it the usual way to test for a logged-in visitor. Output depends only on the AA session state and not on the surrounding item, so views using xuser stay page-cacheable - unlike the related user command, which disables the page cache.

Parameters

field optional default (empty - returns the login name)

Which piece of user information to return. Leave empty for the login name. Use id for the user item long ID. Any other value is taken as a field id or alias of the user item (for example headline........ for the display name, or an alias such as _#SURNAME_) and that field is returned.

Allowed values Leave empty for the login name (the default). Use id for the user item long ID. Any other value is a field id (such as headline........) or alias (such as _#SURNAME_) of the user item.

Examples

virtual{xuser}
Expected(the login name of the current user, e.g. jharrison)
With no argument, returns the login name of the currently logged-in user. Returns an empty string when nobody is logged in. Runtime-dependent on the session, so this is an illustrative example.
virtual{xuser:id}
Expected(the 32-character long ID of the current user item)
The special argument id returns the long ID of the current user item. Feed it into {item:...} or compare it against a relation field to find the user's own content. Empty when nobody is logged in.
virtual{xuser:headline........}
Expected(the headline field of the current user item, e.g. Jane Harrison)
Any other argument is treated as a field id (here headline........) of the user item and that field is returned. Use this for the display name, e-mail, or any reader-management field. Aliases such as _#SURNAME_ work too.
virtual{item:{xuser:id}:_#HEADLINE}
Expected(the display name of the current user, e.g. Jane Harrison)
Reads the display name from the user item with the item command; inside item, use the alias of the user slice, not a field-getter. For an anonymous visitor the id is empty and so is the result.
test{ifset:{xuser}:Welcome back:Please log in}
ExpectedPlease log in
ActualPlease log in
The usual login test: xuser is empty when no reader is logged in through the site login, so ifset prints its else branch. This reference is read without a reader login, so the result here is the anonymous branch; a logged-in reader would see Welcome back.
test[{xuser}] [{xuser:id}] [{xuser:headline........}]
Expected[] [] []
Actual[] [] []
Without a reader logged in through the site login (as when reading this page), every form of xuser gives an empty string - no error, so it is safe on public pages.