<p>You could write <code>{% if not entry.section == 'Homepage' %}</code></p>

<p>Use <code>not</code> to perform a negative test, not a string comparison.</p>

CC BY-SA 3.0
2015-01-08T13:46:36.953Z
2015-01-08T13:46:36.953Z
Paul
<p>This should be what you're looking for:</p>

<pre class="lang-twig prettyprint-override"><code>{% if entry.section not same as('Homepage') %}Blabla {% endif %}
</code></pre>

CC BY-SA 3.0
2018-03-13T17:25:10.677Z
Note that this will compare the translated `name` of the section, not the unique `handle` attribute since the `__toString` function doesn't return the `handle`. Of course it is possible but I would not suggest to do this. The better approach would be to check the handle. When you create a new locale your condition might fail due to different translations for `Homepage`
Robin Schambach
CC BY-SA 3.0
2018-03-13T16:41:23.887Z
2018-03-13T16:41:23.887Z
Jonny
<p>For comparing strings and negating the result I'm using the following construction:</p>
<pre class="lang-twig prettyprint-override"><code>{% set is_training = course_type == 'training' %}
...
{% if not is_training %}
...
</code></pre>

CC BY-SA 4.0
2021-09-24T21:17:20.127Z
2021-10-08T16:10:25.980Z
2021-10-08T16:10:25.980Z
Vlad Moyseenko
<p>Twig <code>!=</code> is a <a href="http://twig.sensiolabs.org/doc/templates.html#comparisons">comparison</a> operator.</p>

<blockquote>
  <p>The following comparison operators are supported in any expression: ==, !=, &lt;, >, >=, and &lt;=</p>
</blockquote>

<p>You can use <code>!=</code> to compare any two things that php lets you compare, and what you get back is a boolean.</p>

<p>Twig <code>not</code> is a <a href="http://twig.sensiolabs.org/doc/templates.html#math">logic</a> operator. (so are <code>and</code> and <code>or</code>)</p>

<blockquote>
  <p>not: Negates a statement.</p>
</blockquote>

CC BY-SA 3.0
2015-01-08T17:40:43.057Z
2015-01-08T17:40:43.057Z
Marion Newlevant
<p>If I write:</p>

<pre><code>{% if entry.section not 'Homepage' %}Blabla {% endif %}
</code></pre>

<p>this results in the error: </p>

<blockquote>
  <p>Unexpected token "operator" of value "not" ("end of statement block"
  expected)</p>
</blockquote>

<p>But if I write: </p>

<pre><code>{% if entry.section != 'Homepage' %}Blabla {% endif %}
</code></pre>

<p>It works.</p>

<p>In the <a href="http://twig.sensiolabs.org/doc/tags/if.html" rel="noreferrer">twig</a> docs there is no mentioning of <code>!=</code> as an operator but it seems to be working just fine. Is <code>!=</code> a craft specific operator?</p>

<p>So whats the difference between <code>not</code> and <code>!=</code> ?</p>

CC BY-SA 3.0
2015-01-08T13:28:30.023Z
I could be wrong, but I believe 'not' is only used for checking values that are 'false'. != (and ==, etc) are for string comparisons.
Steve Abraham
<templating><conditional>
How does the negative (not) conditional work in Twig?
# How does the negative (not) conditional work in Twig?

(Asked by: username_0 on 2015-01-08)

If I write:
{% if entry.section not 'Homepage' %}Blabla {% endif %}

this results in the error: 

Unexpected token "operator" of value "not" ("end of statement block"
  expected)

But if I write: 
{% if entry.section != 'Homepage' %}Blabla {% endif %}

It works.
In the twig docs there is no mentioning of != as an operator but it seems to be working just fine. Is != a craft specific operator?
So whats the difference between not and != ?

**Tags:** templating, conditional

> **Comments:**
> **username_1**: I could be wrong, but I believe 'not' is only used for checking values that are 'false'. != (and ==, etc) are for string comparisons.  

---

## 4 answers

### Answer by username_6 on 2015-01-08. Score: 22 | Accepted answer

Twig `!=` is a [comparison](http://twig.sensiolabs.org/doc/templates.html#comparisons) operator.

> The following comparison operators are supported in any expression: ==, !=, <, >, >=, and <=

You can use `!=` to compare any two things that php lets you compare, and what you get back is a boolean.

Twig `not` is a [logic](http://twig.sensiolabs.org/doc/templates.html#math) operator. (so are `and` and `or`)

> not: Negates a statement.


---

### Answer by username_2 on 2015-01-08. Score: 6

You could write `{% if not entry.section == 'Homepage' %}`

Use `not` to perform a negative test, not a string comparison.


---

### Answer by username_3 on 2018-03-13. Score: 1

This should be what you're looking for:
{% if entry.section not same as('Homepage') %}Blabla {% endif %}

> **Comments:**
> **username_4**: Note that this will compare the translated `name` of the section, not the unique `handle` attribute since the `__toString` function doesn't return the `handle`. Of course it is possible but I would not suggest to do this. The better approach would be to check the handle. When you create a new locale your condition might fail due to different translations for `Homepage`  

---

### Answer by username_5 on 2021-09-24. Score: 1

For comparing strings and negating the result I'm using the following construction:
{% set is_training = course_type == 'training' %}
...
{% if not is_training %}
...


---

