added 3 characters in body
Source Link
Robin Schambach
  • 19.5k
  • 1
  • 18
  • 41

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the advantagedisadvantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed.

For example your user list could look like that

{% set users = craft.users.find() %}
{% for user in users %}
    <!-- everyone can see the firstName of each user -->
    {{ user.firstName }} 
    {% if currentUser %}
        <!-- but only logged in users can see the last name -->
        {{ user.lastName }}
        {% set groupsOfUser = user.getGroups() %}
        {% if groupsOfUser|length %}
            {% if currentUser.isInGroup(groupsOfUser[0]) %}
                <!-- only users of the same group can edit/delete or whatever -->
            {% endif %}
        {% endif %}
    {% endif %}
{% endfor %}

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the advantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed.

For example your user list could look like that

{% set users = craft.users.find() %}
{% for user in users %}
    <!-- everyone can see the firstName of each user -->
    {{ user.firstName }} 
    {% if currentUser %}
        <!-- but only logged in users can see the last name -->
        {{ user.lastName }}
        {% set groupsOfUser = user.getGroups() %}
        {% if groupsOfUser|length %}
            {% if currentUser.isInGroup(groupsOfUser[0]) %}
                <!-- only users of the same group can edit/delete or whatever -->
            {% endif %}
        {% endif %}
    {% endif %}
{% endfor %}

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the disadvantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed.

For example your user list could look like that

{% set users = craft.users.find() %}
{% for user in users %}
    <!-- everyone can see the firstName of each user -->
    {{ user.firstName }} 
    {% if currentUser %}
        <!-- but only logged in users can see the last name -->
        {{ user.lastName }}
        {% set groupsOfUser = user.getGroups() %}
        {% if groupsOfUser|length %}
            {% if currentUser.isInGroup(groupsOfUser[0]) %}
                <!-- only users of the same group can edit/delete or whatever -->
            {% endif %}
        {% endif %}
    {% endif %}
{% endfor %}
added 718 characters in body
Source Link
Robin Schambach
  • 19.5k
  • 1
  • 18
  • 41

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the advantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed.

For example your user list could look like that

{% set users = craft.users.find() %}
{% for user in users %}
    <!-- everyone can see the firstName of each user -->
    {{ user.firstName }} 
    {% if currentUser %}
        <!-- but only logged in users can see the last name -->
        {{ user.lastName }}
        {% set groupsOfUser = user.getGroups() %}
        {% if groupsOfUser|length %}
            {% if currentUser.isInGroup(groupsOfUser[0]) %}
                <!-- only users of the same group can edit/delete or whatever -->
            {% endif %}
        {% endif %}
    {% endif %}
{% endfor %}

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the advantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the advantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed.

For example your user list could look like that

{% set users = craft.users.find() %}
{% for user in users %}
    <!-- everyone can see the firstName of each user -->
    {{ user.firstName }} 
    {% if currentUser %}
        <!-- but only logged in users can see the last name -->
        {{ user.lastName }}
        {% set groupsOfUser = user.getGroups() %}
        {% if groupsOfUser|length %}
            {% if currentUser.isInGroup(groupsOfUser[0]) %}
                <!-- only users of the same group can edit/delete or whatever -->
            {% endif %}
        {% endif %}
    {% endif %}
{% endfor %}
Source Link
Robin Schambach
  • 19.5k
  • 1
  • 18
  • 41

I believe what you're looking for is 'isInGroup'

{% if currentUser.isInGroup('groupHandle') %}

It will also accept an actual group object or a group ID as well.

There is also getGroups:

{{ entry.author.getGroups() }}

So you have several options:

  1. If all users only have one group (so they can not be in two) you can check if the current user is in the same group like the first group of entry.author. But this has the advantage if someone wants to change his/her group the entry will become invisible for the previous group
  2. You could attach the group handle to an entry. So you field create a plainTextField and insert the group handle of the author to this entry -> if the author changes his/her group the entry will still be available for the author as well as everyone who was able to see the entry before.

If you choose the second option you would be able to include the search condition in a ElementCriteriaModel very smooth. And search only entry that is connected by the current group of the currentUser. If someone should be able to see entries but he/she is not allowed to edit them you would just include the isInGroup condition to check if she/he may proceed