User Wrapper

User wrappers provide the properties and methods for interfacing with users via your twig templates. You will be working with a \Enact\template\wrapper\User whenever you are interacting with a user field.

User Properties#

  • id - The unique ID of the user.

  • name - The name of the user.

  • displayName - The display name of the user.

  • handle - The handle of the user.

  • email - The email of the user.

  • createdOn - The date the user was created on.

  • lastAccess - The date the user last logged in.

  • verified - Whether the user is verified.

  • sectionId - The unqiue ID of the section (user group) the user is contained in.

  • sectionHandle - The handle of the section (user group) the user is contained in.

  • sectionName - The name of the section (user group) the user is contained in.

  • entryId - The ID of the entry the tag is associated with (only if users have entries).

  • entryTitle - The title of the entry the user is associated with (only if users have entries).

  • entryUrl - The url of the entry the user is associated with (only if users have entries).

  • imageId - The ID of the asset which acts as the users image.

  • imageUrl - The url of the asset which acts as the users image.

  • imageName - The name of the asset which acts as the users image.

  • imageTitle - The title of the asset which acts as the users image.

Accessing properties

{% set user = entry.yourFieldHandle.userFieldHandle[0] %}

<p>Display Name : {{ user.displayName }}</p>

<p>Email : {{ user.email }}</p>

<p>Last login : {{ user.lastAccess }}</p>

<img src='{{ user.imageUrl }}' title='{{ user.displayName }}'/>

User Methods#

  • getLinkHtml - Returns a a html element with the title and href attributes set that links to the entry the user is associated with (if the user doesn't have an entry it will return an empty string). You can pass an array of attributes to the method to set additional attributes on the a element.

  • getImgHtml - Returns a img html element with the title and src attributes set that displays the users image (if the user doesn't have an imaage it will return an empty string). You can pass an array of attributes to the method to set additional attributes on the img element.

  • getEntry - Returns the \Enact\template\wrapper\Entry representing the entry the user is associated with (if the user doesn't have an entry it will return null).

  • getImgAsset - Return the \Enact\template\wrapper\Asset representing the asset of the users image (if the user doesn't have an image it will return null).

  • hasPermission - Return a boolean specifying if the user has all of the the passed permissions. This function accepts any number of strings, or an array of strings, with each string representing a specific permission.

  • hasAtLeastOnePermission - Return a boolean specifying if the user has at least of the passed permissions. This function accepts any number of strings, or an array of strings, with each string representing a specific permission.

  • isAdmin - Return a boolean specifying if the user is an administrator.

  • tempGrantPermission - Accepts a single string permissions which is then temporarily granted for the life-cycle of the request.

  • tempRevokePermission - Accepts a single string permissions which is then temporarily revoked for the life-cycle of the request.

Using the methods

{% for user in entry.yourFieldHandle.userFieldHandle %}

    {{ user.getLinkHtml({ 'class' : 'user-link' }) }}

    // Will output <a href='/path/to/user/entry' title='Entry Title'>Users display name</a>

    {{ user.getImgHtml }}    

    {% set userEntry = user.getEntry %}

    {{ userEntry.yourFieldHandle }} // prints the field defined by yourFieldHandle

{% endfor %}


// use the currently logged in user

{% if enact.currentUser.hasPermission('create_entry') %}

    // The logged in user can create entries!

{% endif %}