8

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)

nicael
  • 2,382
  • 7
  • 27
  • 48
Roi Agneta
  • 1,463
  • 2
  • 13
  • 21

1 Answers1

21

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'] %}
Lindsey D
  • 23,974
  • 5
  • 53
  • 110
  • 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 '17 at 00:33