2

I'm working on a site that has logins for members, but I'd like to have a page that shows all members with a name and picture. To do this, we had to import an existing database that doesn't have a lot of profile pics. Now I want to hide all users that have no picture uploaded.

This is the code I'm trying, but with no luck...

{% if geslacht_param_string !=''  %}

{% set queryParams = {
    search: {
        query: geslacht_param_string,
        attribute: 'geslacht'               
    },
    geboortedatum : dateRange,
    order :'lastName',
    photo : ':notempty:'
} %}

{% else %}
    {% set queryParams = {
        geboortedatum : dateRange,
        order :'lastName',
        photo : ":notempty:"
    } %}
{% endif %}

{% set leden = craft.users(queryParams) %}

I can't find the decent syntax for :notempty:, can anyone help me out here? Thanks a lot!

2

There's no photo attribute on the UserElementType, so you can't query by it like you're trying.

Completely untested, but you can probably work around that with something like this:

{% if geslacht_param_string !=''  %}

{% set queryParams = {
    search: {
        query: geslacht_param_string,
        attribute: 'geslacht'               
    },
    geboortedatum : dateRange,
    order :'lastName',
} %}

{% else %}
    {% set queryParams = {
        geboortedatum : dateRange,
        order :'lastName',
    } %}
{% endif %}

{% set allUsers = craft.users(queryParams).find() %}

{% set usersWithPhotos = [] %}

{% for user in allUsers %}
    {% if user.photo %}
        {% set usersWithPhotos = usersWithPhotos|merge([user]) %}
    {% endif %}
{% endfor %}

There are {{ usersWithPhotos|length }} users with photos.
2
  • Thanks for the answers, I'll test it ASAP. On a sidenote: the site has about 600 members, won't this slow down the site a lot? – Jan May 13 '16 at 9:26
  • Possible... I'd definitely do some testing. If it's bad, look into using a template hook and a plugin. You can query the database via query builder directly from PHP and cache the results assuming they won't change a lot. – Brad Bell May 14 '16 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.