7

Got myself into a seemingly simple dead-end block with twig syntax. I need to test against multiple items:

{% set segment1 = craft.request.firstSegment %}
{% if segment1 == 'one OR two OR three' %}
DO SOMETHING
{% endif %}

What's going wrong with this bit 'one OR two OR three'? brackets?

8

You've just got quotes wrapped around a simple string. Try something like this instead...

{% if segment1 in ['one','two','three'] %}

That will check to see if your segment1 value is in the array of possible matches.

1
  • Super thanks. I got caught out by the "in"! Oct 8 '14 at 9:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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