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 != ?

  • I could be wrong, but I believe 'not' is only used for checking values that are 'false'. != (and ==, etc) are for string comparisons. Commented Jan 8, 2015 at 13:28

4 Answers 4


Twig != is a comparison 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 operator. (so are and and or)

not: Negates a statement.


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

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


This should be what you're looking for:

{% if entry.section not same as('Homepage') %}Blabla {% endif %}
  • 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 Commented Mar 13, 2018 at 17:25

For comparing strings and negating the result I'm using the following construction:

{% set is_training = course_type == 'training' %}
{% if not is_training %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.