Answers.Body: <p>I'm going to assume that your <code>imageWidth</code> field is a dropdown menu... correct me if I'm wrong. When you output a dropdown fieldtype in your templates, <strong>it's an object, not a string</strong>.</p>
  <hr />
  <h2>Scenario 1: Comparing objects</h2>
  <pre><code>{% if block.imageWidth starts with block.imageWidth %}
  </code></pre>
  <p>The <code>starts with</code> comparison operator is designed for strings, but here it's handling two objects. Makes sense that it would just give up and evaluate to <strong>false</strong>.</p>
  <h2>Scenario 2: Comparing strings</h2>
  <pre><code>{% if '{{ block.imageWidth }}' starts with '{{ block.imageWidth }}' %}
  </code></pre>
  <p>In Twig, you can't nest tags. Those strings are being read literally, and not parsed out into their respective values. So what you've got here is a comparison of two identical strings... Makes sense that this would evaluate to <strong>true</strong>.</p>
  <h2>Scenario 3: Comparing values</h2>
  <pre><code>{% if block.imageWidth.value starts with block.imageWidth.value %}
  </code></pre>
  <p>Working under the assumption that <code>imageWidth</code> is a dropdown menu, then you are actually getting an object from <code>block.imageWidth</code>. Twig isn't confident that you actually want a string here, so you'll need to append <code>.value</code> to specifically get the value of your field.</p>
  <hr />
  <p>I've seen this trip up a few people, but it makes perfect sense once you wrap your head around it. Many objects in Craft will try to automatically &quot;stringify&quot; themselves when output directly using curly braces. But when it's not a direct output tag, you'll generally need to tell Twig that you specifically want the string value, and not the object itself.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-03T05:58:56.063Z
Answers.Text: Great answer, everything is working fine now (and I learned!)
Answers.UserDisplayName: kai
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-03T05:59:53.270Z
Answers.Text: Excellent, happy to help! :)
Answers.UserDisplayName: Lindsey D
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-03T05:34:35.343Z
Answers.LastActivityDate: 2016-02-03T05:34:35.343Z
Answers.LastEditDate: 2020-06-17T08:56:27.903Z
Answers.UserDisplayName: Lindsey D
Body: <p>This evaluates to false</p>
  
  <pre><code>{% if block.imageWidth starts with block.imageWidth %}
  </code></pre>
  
  <p>But this evaluates to true</p>
  
  <pre><code>{% if '{{ block.imageWidth }}' starts with '{{ block.imageWidth }}' %}
  </code></pre>
  
  <p>Some sort of issue with Craft's Twig integration?</p>
  
Tags: <templating>
Title: Twig 'starts with' not evaluating variables properly
ThreadText: # Twig 'starts with' not evaluating variables properly
  
  (Asked by: username_0 on 2016-02-03)
  
  This evaluates to false
  
  ```
  {% if block.imageWidth starts with block.imageWidth %}
  
  ```
  
  But this evaluates to true
  
  ```
  {% if '{{ block.imageWidth }}' starts with '{{ block.imageWidth }}' %}
  
  ```
  
  Some sort of issue with Craft's Twig integration?
  
  **Tags:** templating
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-03. Score: 3 | Accepted answer
  
  I'm going to assume that your `imageWidth` field is a dropdown menu... correct me if I'm wrong. When you output a dropdown fieldtype in your templates, **it's an object, not a string**.
  
  ---
  
  ## Scenario 1: Comparing objects
  
  ```
  {% if block.imageWidth starts with block.imageWidth %}
  
  ```
  
  The `starts with` comparison operator is designed for strings, but here it's handling two objects. Makes sense that it would just give up and evaluate to **false**.
  
  ## Scenario 2: Comparing strings
  
  ```
  {% if '{{ block.imageWidth }}' starts with '{{ block.imageWidth }}' %}
  
  ```
  
  In Twig, you can't nest tags. Those strings are being read literally, and not parsed out into their respective values. So what you've got here is a comparison of two identical strings... Makes sense that this would evaluate to **true**.
  
  ## Scenario 3: Comparing values
  
  ```
  {% if block.imageWidth.value starts with block.imageWidth.value %}
  
  ```
  
  Working under the assumption that `imageWidth` is a dropdown menu, then you are actually getting an object from `block.imageWidth`. Twig isn't confident that you actually want a string here, so you'll need to append `.value` to specifically get the value of your field.
  
  ---
  
  I've seen this trip up a few people, but it makes perfect sense once you wrap your head around it. Many objects in Craft will try to automatically "stringify" themselves when output directly using curly braces. But when it's not a direct output tag, you'll generally need to tell Twig that you specifically want the string value, and not the object itself.
  
  > **Comments:**
  > **username_0**: Great answer, everything is working fine now (and I learned!)  
  > **username_1**: Excellent, happy to help! :)  
  
  ---
  
  