<p>You could do:</p>

<pre class="lang-twig prettyprint-override"><code>{% set otherEntry = craft.entries().section('other').userFieldInOtherEntry("{externalVariable}").one() %}

{% if currentUser in otherEntry.userFieldInOtherEntry %}
    do something
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-01-27T17:20:42.117Z
Thank you Oli, I'll try this solution out and see how it works.
JJefferyDev
CC BY-SA 4.0
2020-01-27T19:34:27.077Z
This suggestion didn't work.  I'll post what ended up working for me.
JJefferyDev
CC BY-SA 4.0
2020-01-24T13:24:43.717Z
2020-01-24T13:24:43.717Z
Oli
<p>I ended up having to go through a for loop checking if the user is related to the current entry, then if statements inside of that for loop.  Is there a cleaner way to do this?</p>

<pre><code>{% if currentUser.isInGroup('userGroup') %}
&lt;p&gt;My Things:&lt;/p&gt;
{% set relatedThings = craft.entries.section('things').relatedTo(currentUser) %}
&lt;ol&gt;
    {% for rel in relatedThings if rel.createdFieldinThing == externalVariable %}
    &lt;li&gt;{{rel.title}} - {{rel.createdFieldinThing}}
        {% if rel.createdFieldinThing == externalVariable %}
                the current user is in the thing
            {% else %}
                the current user is not in the thing
            {% endif %}
        {% endfor %}
    &lt;/li&gt;
&lt;/ol&gt;
{% endif %}
</code></pre>

CC BY-SA 4.0
2020-01-27T19:41:04.267Z
2020-01-27T19:41:04.267Z
JJefferyDev
<p>I am having trouble referencing a user in an if statement:</p>

<pre><code>{% set otherEntry = craft.entries().section('other').userFieldInOtherEntry("{externalVariable}").one() %}

{% if currentUser is relatedTo(otherEntry) %}
    do something
{% endif %}
</code></pre>

<p>I've tried using the for loop method described in the Craft 3 documentation, but I get a recursive loop error.</p>

<templating><craft3><users>
How to reference a user related to entry input in if statement
# How to reference a user related to entry input in if statement

(Asked by: username_0 on 2020-01-24)

I am having trouble referencing a user in an if statement:
{% set otherEntry = craft.entries().section('other').userFieldInOtherEntry("{externalVariable}").one() %}

{% if currentUser is relatedTo(otherEntry) %}
    do something
{% endif %}

I've tried using the for loop method described in the Craft 3 documentation, but I get a recursive loop error.

**Tags:** templating, craft3, users

---

## 2 answers

### Answer by username_1 on 2020-01-24. Score: 2

You could do:
{% set otherEntry = craft.entries().section('other').userFieldInOtherEntry("{externalVariable}").one() %}

{% if currentUser in otherEntry.userFieldInOtherEntry %}
    do something
{% endif %}

> **Comments:**
> **username_0**: Thank you Oli, I'll try this solution out and see how it works.  
> **username_0**: This suggestion didn't work.  I'll post what ended up working for me.  

---

### Answer by username_0 on 2020-01-27. Score: 0

I ended up having to go through a for loop checking if the user is related to the current entry, then if statements inside of that for loop.  Is there a cleaner way to do this?
{% if currentUser.isInGroup('userGroup') %}
My Things:
{% set relatedThings = craft.entries.section('things').relatedTo(currentUser) %}

    {% for rel in relatedThings if rel.createdFieldinThing == externalVariable %}
    {{rel.title}} - {{rel.createdFieldinThing}}
        {% if rel.createdFieldinThing == externalVariable %}
                the current user is in the thing
            {% else %}
                the current user is not in the thing
            {% endif %}
        {% endfor %}
    

{% endif %}


---

