User Lookup

Search for and retrieve users in you twig templates using the user lookup. Perform a lookup by calling enact.user and defining a method chain of property/value pairs specifying the conditions under which to lookup users. Every property defined by the User Wrapper is available as a method on the lookup, call the property you want to use as a condition, passing it a value. By default each value is compared to the property by being exactly equal (in SQL just property=value), but you can prefix your values with the below comparators to specify a different comparison (always include a space after the comparator):

  • > - Where property is greater than the value.

  • < - Where property is less than the value.

  • >= - Where property is greater than or equal to the value.

  • <= - Where property is less than or equal to the value.

  • ! - Where the property does not equal the value.

  • LIKE - Where the property contains the value.

Basic example

//get all the users in the contributors section

{% set contributors = enact.user.sectionHandle('contributors').fetch %}

When you are done specifying your conditions, call the method fetch to return the array of matching users, each represented as a \Enact\template\wrapper\User. You may also use the first and last method to retrieve the first or last user returned from the lookup. Both methods use the fetch method internally.

Loop the results

<p>{{ contributors|length }} contributors</p>


{% for contributor in contributors %}

    <li>{{ contributor.displayName }} {{ contributor.getImgHtml }}</li>

{% endfor %}


More examples

//get users who have logged in within the last day

{% set oneDayAgo = 'now'|date_modify('-1 day')|date('Y-m-d') %}

{% set users = enact.user.lastAccess('>= ' ~ oneDayAgo).fetch %}

//find the user with the handle 'timmy'

{% set timmy = enact.user.handle('timmy').first %}

//find all the users who have images

{% set users = enact.user.imageName('! null').fetch %}
Search method

Use the search method to perform a LIKE comparison on the user name, handle, and displayName properties simultaneously.

{% set users ='tim').fetch %}
Order method

Use the order method to sort the result of the lookup, passing a property name and and optional sort type (ASC, DESC), by default ASC is used.

{% set users = enact.user.sectionHandle('contributors').order('displayName ASC').fetch %}
Limit method

Limit the number of users returned by the lookup

{% set users = enact.user.sectionHandle('contributors').limit(10).fetch %}
Page method

Use the page method in conjunction with the limit method to return a specific number of users from a specific page of the results.

// will return users 10-15

{% set users = enact.user.sectionHandle('contributors').limit(5).page(3).fetch %}
Total method

Use the total method to force the lookup to return an integer value specifying the number of users that matched the condition. The same can be accomplished using the twig length filter, however, this prevents the actual users from being fetched and returned, saving database resources.

{% set totalUsers = enact.user.sectionHandle('contributors').total.fetch %}