<p>You don't need the <code>for</code> loop in this case. What's happening is you're looping over each option in your dropdown field, and each time it's checking the value of the dropdown and displaying <code>white</code> or <code>black</code>. Since you have three options, you're going to get the dropdown value displayed three times (which is why you're seeing <code>black</code> <code>black</code> <code>black</code>).</p>

<p>All you need is just the <code>if</code> conditional:</p>

<pre><code>{% if entry.transparentMenu.value == "menuLight" %}
    &lt;h3&gt;white&lt;/h3&gt;
{% elseif entry.transparentMenu.value == "menuDark" %}
    &lt;h3&gt;black&lt;/h3&gt;
{% endif %}
</code></pre>

<blockquote>
  <p>Also, fwiw looks like you have a typo in your code ️ - you use <code>entry.transparentMenu</code> twice and <code>entry.header.transparentMenu</code> once. I'm guessing you want <code>entry.transparentMenu</code> everywhere...</p>
</blockquote>

<p>The only time you'd want to use the <code>for</code> loop to get all the dropdown field's options is if you wanted to display those in the template (in a list for example or to create your own dropdown on the frontend):</p>

<pre><code>&lt;ul&gt;
    {% for option in entry.dropdownFieldHandle.options %}
        &lt;li&gt;{{ option }}&lt;/li&gt;
    {% endfor %}
&lt;/ul&gt;
</code></pre>

<p>But in your case, you just want the current value and not all the options, so just remove the <code>for</code> loop.</p>

CC BY-SA 4.0
2018-12-19T14:08:29.787Z
Thanks man! That's it! I thought the for loop is important because in the matrix field you need it
adsfgfhg
CC BY-SA 4.0
2018-12-19T14:14:45.917Z
For sure! So the difference is a matrix field has different blocks that you would loop over, but with a dropdown field you can quickly grab the value, which is all you need in this instance. There are cases where you would want to use a `for` loop to access the dropdown options in your template, but that's not super common. It all just depends on how you're using your dropdown field 
Jalen Davenport
CC BY-SA 4.0
2018-12-19T14:02:25.160Z
2018-12-19T14:02:25.160Z
Jalen Davenport
<p>I don't know your structure, but if <code>transparentMenu</code> is a select or checkbox or something with <code>menuLight</code> and <code>menuDark</code> as options, it should be:</p>

<p><code>{% for option in entry.transparentMenu.options %}
        {% if entry.header.transparentMenu.value == "menuLight" %}
            &lt;h3&gt;white&lt;/h3&gt;
        {% elseif entry.header.transparentMenu.value == "menuDark" %}
            &lt;h3&gt;black&lt;/h3&gt;
        {% endif %}
    {% endfor %}</code></p>

<p>instead of:</p>

<p><code>{% for option in entry.transparentMenu.options %}
        {% if entry.transparentMenu.value == "menuLight" %}
            &lt;h3&gt;white&lt;/h3&gt;
        {% elseif entry.header.transparentMenu.value == "menuDark" %}
            &lt;h3&gt;black&lt;/h3&gt;
        {% endif %}
    {% endfor %}</code></p>

<p>right?</p>

CC BY-SA 4.0
2018-12-19T14:02:17.200Z
2018-12-19T14:02:17.200Z
Ash Joseph
<p>I have a dropdown field that has three options. In my template, I want to do one thing if option 1 is selected and do something else if option 2 is selected.</p>

<p>Here is what my code looks like:</p>

<pre><code>{% for option in entry.transparentMenu.options %}
    {% if entry.transparentMenu.value == "menuLight" %}
        &lt;h3&gt;white&lt;/h3&gt;
    {% elseif entry.transparentMenu.value == "menuDark" %}
        &lt;h3&gt;black&lt;/h3&gt;
    {% endif %}
{% endfor %}
</code></pre>

<p>The code seems to work but the output is: <code>black</code> <code>black</code> <code>black</code>; I only want <code>black</code> to display once.</p>

<p>What am I doing wrong?</p>

<craft3><drop-down>
Dropdown field value getting outputted multiple times
# Dropdown field value getting outputted multiple times

(Asked by: username_0 on 2018-12-19)

I have a dropdown field that has three options. In my template, I want to do one thing if option 1 is selected and do something else if option 2 is selected.
Here is what my code looks like:
{% for option in entry.transparentMenu.options %}
    {% if entry.transparentMenu.value == "menuLight" %}
        white
    {% elseif entry.transparentMenu.value == "menuDark" %}
        black
    {% endif %}
{% endfor %}

The code seems to work but the output is: black black black; I only want black to display once.
What am I doing wrong?

**Tags:** craft3, drop-down

---

## 2 answers

### Answer by username_1 on 2018-12-19. Score: 1 | Accepted answer

You don't need the for loop in this case. What's happening is you're looping over each option in your dropdown field, and each time it's checking the value of the dropdown and displaying white or black. Since you have three options, you're going to get the dropdown value displayed three times (which is why you're seeing black black black).
All you need is just the if conditional:
{% if entry.transparentMenu.value == "menuLight" %}
    white
{% elseif entry.transparentMenu.value == "menuDark" %}
    black
{% endif %}


Also, fwiw looks like you have a typo in your code ️ - you use entry.transparentMenu twice and entry.header.transparentMenu once. I'm guessing you want entry.transparentMenu everywhere...

The only time you'd want to use the for loop to get all the dropdown field's options is if you wanted to display those in the template (in a list for example or to create your own dropdown on the frontend):

    {% for option in entry.dropdownFieldHandle.options %}
        {{ option }}
    {% endfor %}


But in your case, you just want the current value and not all the options, so just remove the for loop.

> **Comments:**
> **username_0**: Thanks man! That's it! I thought the for loop is important because in the matrix field you need it  
> **username_1**: For sure! So the difference is a matrix field has different blocks that you would loop over, but with a dropdown field you can quickly grab the value, which is all you need in this instance. There are cases where you would want to use a `for` loop to access the dropdown options in your template, but that's not super common. It all just depends on how you're using your dropdown field   

---

### Answer by username_2 on 2018-12-19. Score: -1

I don't know your structure, but if `transparentMenu` is a select or checkbox or something with `menuLight` and `menuDark` as options, it should be:

`{% for option in entry.transparentMenu.options %}
{% if entry.header.transparentMenu.value == "menuLight" %}

### white

{% elseif entry.header.transparentMenu.value == "menuDark" %}

### black

{% endif %}
{% endfor %}`

instead of:

`{% for option in entry.transparentMenu.options %}
{% if entry.transparentMenu.value == "menuLight" %}

### white

{% elseif entry.header.transparentMenu.value == "menuDark" %}

### black

{% endif %}
{% endfor %}`

right?


---

