{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: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{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{item:{xuser:id}:_#HEADLINE}
Expected(the display name of the current user, e.g. Jane Harrison)
A common real-world pattern: take the current user long ID with {xuser:id} and feed it to {item:...} to read a field of that user item (here the _#HEADLINE alias for the display name). Equivalent to {xuser:headline........}.
virtual{ifset:{xuser}:Welcome back:Please log in}
ExpectedWelcome back (when logged in) / Please log in (when anonymous)
ActualPlease log in
Because {xuser} is empty for anonymous visitors, {ifset:{xuser}:...:...} is the usual way to branch on whether someone is logged in. The first text shows to logged-in users, the second to everyone else.