Is it not possible to define multiple conditions in an if statement?

{% if foo == 'x' || foo == 'y' %}

I tried this and got an error:

Unexpected token "punctuation" of value "|" ("name" expected)

  • Thanks, all! I had originally tried "AND" but it did not work. Does in lowercase!!
    – Roi Agneta
    Oct 5, 2014 at 19:08

1 Answer 1


Twig doesn't accept || or &&... Try using or and and instead.

{% if foo == 'x' or foo == 'y' %}

Important to note, they must be lowercase.

You may also want to take a look at this question, which shows another way to write a similar condition:

{% if foo in ['x', 'y'] %}
  • Ah thanks for the "They must be lowercase" note. I wondered why I couldn't get such a simple bit of logic working :)
    – JamesNZ
    Jan 31, 2017 at 0:33

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.