Answers.Body: <p>A checkboxes field returns an array of models, that you can inspect using <code>{{ dump(sourceCountry) }}</code> in your loop.</p>
  
  <p>The model has a <code>__toString</code> method that outputs the checkbox value when you output the model using <code>{{ sourceCountry }}</code>. This magic method doesn’t do its thing when you use the model in a comparison operator, so you are currently comparing a model to a string.</p>
  
  <p>Access the value property directly and your conditional should work.</p>
  
  <pre><code>{% if sourceCountry.value == 'GB' %} 
      {% set visibility = true %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T15:50:23.533Z
Answers.Text: I knew I'm missing something obvious, thanks Carl
Answers.UserDisplayName: Lukigi
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-12T15:07:19.930Z
Answers.LastActivityDate: 2017-01-12T15:07:19.930Z
Answers.UserDisplayName: carlcs
Body: <p>I'm new to Twig, and I'm struggling to compare a value from a checkbox with a value from a drop-down</p>
  
  <pre><code>   {# sourceCountry - checkbox with a list of countries #}
     {# currentUser.country - dropdown with a list of countries #}
  
     {% for sourceCountry in region.targetCountries %}
        {{ sourceCountry }} = {{ currentUser.country }}   &lt;br&gt;
        {{ dump(sourceCountry == currentUser.country) }}
        {% if sourceCountry == currentUser.country %} 
           {% set visibility = true %}
        {% endif %}
     {% endfor %}
  </code></pre>
  
  <p>The result I'm getting from this is: </p>
  
  <p>GB = GB</p>
  
  <p>bool(false)</p>
  
  <p>Most likely something to do with variable types, but no idea how to solve this. I've searched for some Twig 'to string' conversions, but no luck.</p>
  
Tags: <templating><drop-down><checkboxes>
Title: Drop-down and checkbox in a condition
ThreadText: # Drop-down and checkbox in a condition
  
  (Asked by: username_0 on 2017-01-12)
  
  I'm new to Twig, and I'm struggling to compare a value from a checkbox with a value from a drop-down
  
  ```
     {# sourceCountry - checkbox with a list of countries #}
     {# currentUser.country - dropdown with a list of countries #}
  
     {% for sourceCountry in region.targetCountries %}
        {{ sourceCountry }} = {{ currentUser.country }}   <br>
        {{ dump(sourceCountry == currentUser.country) }}
        {% if sourceCountry == currentUser.country %} 
           {% set visibility = true %}
        {% endif %}
     {% endfor %}
  
  ```
  
  The result I'm getting from this is:
  
  GB = GB
  
  bool(false)
  
  Most likely something to do with variable types, but no idea how to solve this. I've searched for some Twig 'to string' conversions, but no luck.
  
  **Tags:** templating, drop-down, checkboxes
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-12. Score: 2 | Accepted answer
  
  A checkboxes field returns an array of models, that you can inspect using `{{ dump(sourceCountry) }}` in your loop.
  
  The model has a `__toString` method that outputs the checkbox value when you output the model using `{{ sourceCountry }}`. This magic method doesn’t do its thing when you use the model in a comparison operator, so you are currently comparing a model to a string.
  
  Access the value property directly and your conditional should work.
  
  ```
  {% if sourceCountry.value == 'GB' %} 
      {% set visibility = true %}
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: I knew I'm missing something obvious, thanks Carl  
  
  ---
  
  