Users Field

Stores any number of users from the CMS

Options#

  • User Group (optional) – The user group users can be selected from.

  • Custom Label – A custom label users will see when adding users to the field. Default is “Add User”, the word “User” is what will be replaced with your custom label.

  • Limit – How many users can be selected.

Use#

When a user clicks the “Add User” or “Add {your custom label}” button a modal will popup allowing for the selection of a user. If the restrict selection was set to a specific section then only users in the section will be made available for selection.

A user is then selected by clicking on them.

If the field has been set to required then the entry will not be update-able until at least one user has been selected.

If the field has a limit set, then only that number of users will be allowed to be selected. Once the limit has been reached the button to add more users will disappear. If the limit is modified at a later date, and the field contains more than the new limit, an error will be shown notifying the user that they must remove users from the field to match the new limit.

Template Use#

Access your users fields via the handle you set for the field. Each users field provides an array accessed via userFieldHandle which contains the users stored in the field, in the order set by the content creators.

{% set users = entry.yourFieldHandle.userFieldHandle %}

Each user in the userFieldHandle array is an instance of a \Enact\template\wrapper\User, which provides properties and method for interfacing with each user via your twig templates.

Examples#

The loop

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

    <p>{{ user.name }}</p>

{% endfor %}

Check if the field contains users

{% if entry.yourFieldHandle.userFieldHandle | length %}

    {{ entry.yourFieldHandle.userFieldHandle[0].displayName }}

{% endif %}

// or test the 0 index of the array

{% if entry.yourFieldHandle.userFieldHandle[0] %}

    {{ entry.yourFieldHandle.userFieldHandle[0].getImgHtml }}

{% endif %}

Basic usage

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

{% if user %}

    <a href='{{ user.entryUrl }}' >{{ user.displayName }} - {{ user.createdOn }}</a>

{% endif %}