<p>In Craft there are several so called <a href="https://docs.craftcms.com/v2/templating/global-variables.html" rel="nofollow noreferrer">global variables</a> one of them is the <code>currentUser</code> thus you can check if someone is logged in with </p>

<pre><code>{% if currentUser %} 

{% else %} 

{% endif %} 
</code></pre>

<p>You don't need to loop a user array </p>

CC BY-SA 4.0
2018-05-05T16:04:44.897Z
aaah ok can I still target a certain user from the 'users group' with this {% if currentUser in craft.users.groups('nomads') %} As I am pulling some information so the form is already populated
Zack Reid
CC BY-SA 4.0
2018-05-05T16:11:34.650Z
Please read this https://craftcms.stackexchange.com/questions/1087/check-user-is-in-user-group-custom-user-permissions
Robin Schambach
CC BY-SA 4.0
2018-05-05T15:27:29.893Z
2018-05-05T15:27:29.893Z
Robin Schambach
<p>I have implemented an if/else statement and when I add the information to the 'else' part it outputs three duplicates of the same content.</p>

<p>I am calling the if statement to check if the user is signed in here more andless.
If they are they will get a booking form which shows up fine and only one of them.</p>

<pre><code>{% for user in craft.users.groups('nomad') %}
{% if user.isCurrent %}
&lt;div class="wrapper"&gt;
&lt;form method="post" action="" accept-charset="UTF-8"&gt;
    {{ getCsrfInput() }}

    {% for entry in craft.entries.section('studios').search(studio) %}
        &lt;input type="hidden" name="fields[studioEmail]" value="{{ entry.email 
    }}"&gt;
    {% endfor %}
    &lt;input type="hidden" name="action" 
    value="amForms/submissions/saveSubmission"&gt;
    &lt;input type="hidden" name="handle" value="bookingForm"&gt;

    {# Optional: Redirect URL. Will redirect to current page by default. #}
    &lt;input type="hidden" name="redirect" value="booking-form/thank-you"&gt;

    {{ craft.amForms.displayAntispam() }}


            &lt;div class="input__wrapper"&gt;
                &lt;label for="fields-firstName" class="sr-only"&gt;First 
     Name&lt;/label&gt;
                &lt;input type="text" id="fields-firstName" 
      name="fields[firstName]" autocomplete="off" placeholder="First Name" 
     value="{{ currentUser.firstName }}"&gt;
            &lt;/div&gt;

            &lt;div class="input__wrapper"&gt;
                &lt;label for="fields-lastName" class="sr-only"&gt;Last Name&lt;/label&gt;
                &lt;input type="text" id="fields-lastName" 
               name="fields[lastName]" autocomplete="off" placeholder="Last 
               Name" value="{{ currentUser.lastName }}"&gt;
            &lt;/div&gt;

            &lt;div class="input__wrapper"&gt;
                &lt;label for="fields-mobileNumber" class="sr-only"&gt;Mobile Number&lt;/label&gt;
                &lt;input type="text" id="fields-mobileNumber" name="fields[mobileNumber]" autocomplete="off" placeholder="Mobile Number" value="{{ currentUser.mobileNumber }}"&gt;
            &lt;/div&gt;

            &lt;div class="input__wrapper"&gt;
                &lt;label for="fields-startDate" class="sr-only"&gt;Start 
                Date&lt;/label&gt;
                &lt;input type="text" id="fields-startDate" 
                name="fields[startDate]" autocomplete="off" placeholder="start 
        Date"&gt;
            &lt;/div&gt;

            &lt;div class="input__wrapper"&gt;
                &lt;label for="fields-endDate" class="sr-only"&gt;End Date&lt;/label&gt;
                &lt;input type="text" id="fields-endDate" name="fields[endDate]" 
                autocomplete="off" placeholder="End Date"&gt;
            &lt;/div&gt;

            &lt;div class="input__wrapper"&gt;
                &lt;label for="fields-studio" class="sr-only"&gt;Studio&lt;/label&gt;
                &lt;select name="fields[studio]" id="fields-studio"&gt;
                    {% for entry in craft.entries.section('studios').find() %}
                        &lt;option value="{{ entry.title }}"

                        {% if studio == entry.title %}
                                selected="selected"
                        {% endif %}


                        &gt;{{ entry.title }}&lt;/option&gt;
                    {% endfor %}
                &lt;/select&gt;
            &lt;/div&gt;



    &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  &lt;/div&gt;
</code></pre>

<p>Then this is the else statement. I think I might need to add something to the     {% else %}. Though I don't see why it would be outputting three duplicates of the same content in the first place.</p>

<pre><code>  {% else %}
  &lt;section class="form__wrapper"&gt;
  &lt;div class="content__form_wrapper sign-up_wrapper"&gt;
    &lt;h1&gt;Become a Digital Nomad and join the community&lt;/h1&gt;
    &lt;p&gt;You need to be a member to rent a desk, it will only take a moment of   
    your and you will be on your way.&lt;/p&gt;

    &lt;a href="{{ siteUrl }}users/sign-up" class=""&gt;Sign Up&lt;/a
&lt;/div&gt;
&lt;/section&gt;
{% endif %}
{% endfor %}
</code></pre>

<p>Thanks for the help :)</p>

CC BY-SA 4.0
2018-05-05T12:11:35.963Z
Maybe because there is a loop? It will output the content for each user in the group
Robin Schambach
CC BY-SA 4.0
2018-05-05T14:38:02.263Z
Yea it seems to be pulling in for each 'user', will try to fix it now.. Thanks for the help :)
Zack Reid
CC BY-SA 4.0
2018-05-05T15:06:49.547Z
Why do you even use this loop? It really makes no sense at all
Robin Schambach
CC BY-SA 4.0
2018-05-05T15:21:07.143Z
To be honest I didn't even know this was a loop :/..  I am just trying to display a form if the user is logged in. If they are not it won't show and sign up button will instead.. I thought an if/else statement would be the way todo this?
Zack Reid
<users><current-user>
Else statement outputting three bits of content
# Else statement outputting three bits of content

(Asked by: username_0 on 2018-05-05)

I have implemented an if/else statement and when I add the information to the 'else' part it outputs three duplicates of the same content.
I am calling the if statement to check if the user is signed in here more andless.
If they are they will get a booking form which shows up fine and only one of them.
{% for user in craft.users.groups('nomad') %}
{% if user.isCurrent %}


    {{ getCsrfInput() }}

    {% for entry in craft.entries.section('studios').search(studio) %}
        
    {% endfor %}
    
    

    {# Optional: Redirect URL. Will redirect to current page by default. #}
    

    {{ craft.amForms.displayAntispam() }}


            
                First 
     Name
                
            

            
                Last Name
                
            

            
                Mobile Number
                
            

            
                Start 
                Date
                
            

            
                End Date
                
            

            
                Studio
                
                    {% for entry in craft.entries.section('studios').find() %}
                        {{ entry.title }}
                    {% endfor %}
                
            



    
  
  

Then this is the else statement. I think I might need to add something to the     {% else %}. Though I don't see why it would be outputting three duplicates of the same content in the first place.
  {% else %}
  
  
    Become a Digital Nomad and join the community
    You need to be a member to rent a desk, it will only take a moment of   
    your and you will be on your way.

    Sign Up

{% endif %}
{% endfor %}

Thanks for the help :)

**Tags:** users, current-user

> **Comments:**
> **username_1**: Maybe because there is a loop? It will output the content for each user in the group  
> **username_0**: Yea it seems to be pulling in for each 'user', will try to fix it now.. Thanks for the help :)  
> **username_1**: Why do you even use this loop? It really makes no sense at all  
> **username_0**: To be honest I didn't even know this was a loop :/..  I am just trying to display a form if the user is logged in. If they are not it won't show and sign up button will instead.. I thought an if/else statement would be the way todo this?  

---

## 1 answers

### Answer by username_1 on 2018-05-05. Score: 1

In Craft there are several so called global variables one of them is the currentUser thus you can check if someone is logged in with 
{% if currentUser %} 

{% else %} 

{% endif %} 

You don't need to loop a user array

> **Comments:**
> **username_0**: aaah ok can I still target a certain user from the 'users group' with this {% if currentUser in craft.users.groups('nomads') %} As I am pulling some information so the form is already populated  
> **username_1**: Please read this https://craftcms.stackexchange.com/questions/1087/check-user-is-in-user-group-custom-user-permissions  

---

