Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-27T17:20:42.117Z
Answers.Text: Thank you Oli, I'll try this solution out and see how it works.
Answers.UserDisplayName: JJefferyDev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-27T19:34:27.077Z
Answers.Text: This suggestion didn't work.  I'll post what ended up working for me.
Answers.UserDisplayName: JJefferyDev
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-24T13:24:43.717Z
Answers.LastActivityDate: 2020-01-24T13:24:43.717Z
Answers.UserDisplayName: Oli
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-27T19:41:04.267Z
Answers.LastActivityDate: 2020-01-27T19:41:04.267Z
Answers.UserDisplayName: JJefferyDev
Body: <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>
  
Tags: <templating><craft3><users>
Title: How to reference a user related to entry input in if statement
ThreadText: # 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:
  
  ```twig
  {% 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') %}
  <p>My Things:</p>
  {% set relatedThings = craft.entries.section('things').relatedTo(currentUser) %}
  <ol>
      {% for rel in relatedThings if rel.createdFieldinThing == externalVariable %}
      <li>{{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 %}
      </li>
  </ol>
  {% endif %}
  
  ```
  
  
  ---
  
  