0

I'm trying to achieve something quite simple.

My code is the following:

{% if template != 'index' or template != 'page.jump' %}

I then want to do something if the template isn't equal to those two pages.

However, it doesn't seem to be interpreting anything after or

Either of these work individually, and I've had to resort to nesting if statements which is nasty.

Is there any reason why template won't work with the or operator in a liquid template?

James
  • 608
  • 6
  • 11
  • 1
    old question I know, but for future searchers: the problem isn't with liquid, it's with your logic -- if you want to do something if the template isn't equal to either of those pages, then `or` is not the right operator here (which is why `and` works below). once you hit `!= 'index' you evaluate to true. so you just had a fundamental misunderstanding of boolean logic. – nsheff Jun 29 '18 at 17:21

2 Answers2

4

Try the "and" operator.

{% if template != "index" and template != "page.jump" %}

There seems to be another way around here: How to use multiple arguments in an if statement with Liquid

Community
  • 1
  • 1
jlcharette
  • 900
  • 8
  • 17
  • This works perfectly. Not sure why I didn't think of that. Strange how the or operator doesn't work here though. Thanks – James Apr 17 '15 at 07:23
  • 1
    XOR (exclusive OR) only works (returns true) if one of the statement is true but not both at the same time. That's why you have to use 'and'. http://en.wikipedia.org/wiki/Exclusive_or. Please mark as accepted answer. Have a nice day! – jlcharette Apr 22 '15 at 20:00
0

For the liquid it works perfectly in 2 conditions:

  1. Don't use double quotes, just single quotes
  2. Don't start your statement with "Not Equal" != You can use != as the second part of your statement

Example:

{% if product.type == 'Bundle' and product.type != 'Dress'%}
JON
  • 965
  • 2
  • 10
  • 28
Karo
  • 1