<p>You'll want to use:</p>

<pre><code>{% set mylevel = currentUser.level.value %}
</code></pre>

<p>If you just use <code>currentUser.level</code> and assign it to a variable, then what you'll get back is a <a href="https://craftcms.com/classreference/fieldtypes/MultiOptionsFieldData" rel="nofollow noreferrer">MultiOptionsFieldData</a> class, instead of the value you are expecting.</p>

<p>There is a note on the bottom of the <a href="https://craftcms.com/docs/dropdown-fields" rel="nofollow noreferrer">page here</a> that describes it.</p>

CC BY-SA 3.0
2017-01-25T21:26:27.717Z
2017-01-25T21:26:27.717Z
Brad Bell
<p>I'm not sure if this is a bug or not, but there is something weird going on if I try to compare an integer form a dropdown field to an integer in the template. In short, it doesn't work.</p>

<p>I'm working with a dropdown level field for users from 1 to 15 and use conditionals for content:</p>

<pre><code>{% set integer = 7 %}
{% set mylevel = currentUser.level %}

My level: {{mylevel}}&lt;br&gt;
Number: {{integer}}&lt;br&gt;&lt;br&gt;

{% if mylevel &gt;= integer %}
    {{mylevel}} bigger than or equals {{integer}}
{% else %}
    {{mylevel}} smaller than {{integer}}    
{% endif %}
</code></pre>

<p>This outputs:</p>

<pre><code>My level: 8&lt;br&gt;
Number: 7&lt;br&gt;&lt;br&gt;
8 smaller than 7
</code></pre>

<p>HOWEVER if I replace the code "currentUser.level" with 8 like:</p>

<pre><code>{% set integer = 7 %}
{% set mylevel = 8 %}

My level: {{mylevel}}&lt;br&gt;
Number: {{integer}}&lt;br&gt;&lt;br&gt;

{% if mylevel &gt;= integer %}
    {{mylevel}} bigger than or equals {{integer}}
{% else %}
    {{mylevel}} smaller than {{integer}}    
{% endif %}
</code></pre>

<p>Then the output is:</p>

<pre><code>My level: 8
Number: 7
8 bigger than or equals 7
</code></pre>

<p>I checked the database and reinserted all numbers, but nothing changes.</p>

<p>Database had this:</p>

<pre><code>{"options":[{"label":"SG1","value":"1","default":""},{"label":"SG2","value":"2","default":""},{"label":"SG3","value":"3","default":""},{"label":"SG4","value":"4","default":""},{"label":"SG5","value":"5","default":""},{"label":"SG6","value":"6","default":""},{"label":"SG7","value":"7","default":""},{"label":"SG8","value":"8","default":""},{"label":"SG9","value":"9","default":""},{"label":"SG10","value":"10","default":""},{"label":"SG11","value":"11","default":""},{"label":"SG12","value":"12","default":""},{"label":"TG01","value":"13","default":""},{"label":"TG02","value":"14","default":""},{"label":"TG03","value":"15","default":""},{"label":"TG04","value":"16","default":""}]}
</code></pre>

CC BY-SA 3.0
2017-01-25T17:56:56.467Z
When you output the {{currentUser.level}} in your templates what does it give you?
Jan_dh
CC BY-SA 3.0
2017-01-25T19:18:06.527Z
This outputs 8 as you can see in the second example block
noregt
<templating><conditional><integer><comparisons>
Comparison with an integer from a dropdown list not working
# Comparison with an integer from a dropdown list not working

(Asked by: username_0 on 2017-01-25)

I'm not sure if this is a bug or not, but there is something weird going on if I try to compare an integer form a dropdown field to an integer in the template. In short, it doesn't work.
I'm working with a dropdown level field for users from 1 to 15 and use conditionals for content:
{% set integer = 7 %}
{% set mylevel = currentUser.level %}

My level: {{mylevel}}
Number: {{integer}}

{% if mylevel >= integer %}
    {{mylevel}} bigger than or equals {{integer}}
{% else %}
    {{mylevel}} smaller than {{integer}}    
{% endif %}

This outputs:
My level: 8
Number: 7
8 smaller than 7

HOWEVER if I replace the code "currentUser.level" with 8 like:
{% set integer = 7 %}
{% set mylevel = 8 %}

My level: {{mylevel}}
Number: {{integer}}

{% if mylevel >= integer %}
    {{mylevel}} bigger than or equals {{integer}}
{% else %}
    {{mylevel}} smaller than {{integer}}    
{% endif %}

Then the output is:
My level: 8
Number: 7
8 bigger than or equals 7

I checked the database and reinserted all numbers, but nothing changes.
Database had this:
{"options":[{"label":"SG1","value":"1","default":""},{"label":"SG2","value":"2","default":""},{"label":"SG3","value":"3","default":""},{"label":"SG4","value":"4","default":""},{"label":"SG5","value":"5","default":""},{"label":"SG6","value":"6","default":""},{"label":"SG7","value":"7","default":""},{"label":"SG8","value":"8","default":""},{"label":"SG9","value":"9","default":""},{"label":"SG10","value":"10","default":""},{"label":"SG11","value":"11","default":""},{"label":"SG12","value":"12","default":""},{"label":"TG01","value":"13","default":""},{"label":"TG02","value":"14","default":""},{"label":"TG03","value":"15","default":""},{"label":"TG04","value":"16","default":""}]}

**Tags:** templating, conditional, integer, comparisons

> **Comments:**
> **username_1**: When you output the {{currentUser.level}} in your templates what does it give you?  
> **username_0**: This outputs 8 as you can see in the second example block  

---

## 1 answers

### Answer by username_2 on 2017-01-25. Score: 1 | Accepted answer

You'll want to use:
{% set mylevel = currentUser.level.value %}

If you just use currentUser.level and assign it to a variable, then what you'll get back is a MultiOptionsFieldData class, instead of the value you are expecting.
There is a note on the bottom of the page here that describes it.


---

