You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To work around this, I've always used nested if/unless statements, which isn't pretty but it works.
So, if you have this in a language that has a not operator:
ifa && b && !c# ...end
then you can do this in Liquid:
{% if a and b %}
{% unless c %}
...
{% endunless %}
{% endif %}
It can get tricky if you need complex else logic, but most times this works for me.
Reacted by N02870941, Courtney Pitcher, Mihail Nikolov, Vlad GURDIGA, Tobias B aka The_Minefighter, Jeremy Grifski, Arthur, Kiara Bickers, Stefan Schneider, Trey Piepmeier and 6 more
@dapengme what is your specific usecase? you can also use var != 'value'
Reacted by Aziz Abbas, Jim Fisher, Russell Davis, Manuel Zubieta, Matthew Fletcher, Gabriele Tomberli, ECCresym, abel1502, rubenwardy, Timothy Harding and 2 more
That works only for simple, not combined conditions. I've worked around it, but "not" is a legitimate boolop that is not entirely replacable by unless.
Reacted by Addie GS, Zoltan Kundi, Its me VOID, Gabriele Tomberli and Timothy Harding
Sometimes it would make a lot more sense to have things that behave like "does not contain", rather than an "unless" statement. It would keep things cleaner and offer more options.
Reacted by Benjamin Ashbaugh, Old, Deadly Engineer, Addie GS, Zoltan Kundi, Gabriele Tomberli, Timothy Harding and Pikamander2
I agree with Cam and AllThatIsTheCase. It is difficult to check if, for example, a collection of product.tags and customer.tags do not contain the tag "wholesale" without a "not contains" operator because of the combined condition.
same way having support for parentheses would be nice to have
Ah. Sounds like the problem is the parser support for not, because you're not using a parser generator or something like that — and you can't parse the context free grammar of expressions with parentheses with regular expressions such as
We could totally implement parentheses with the new parsers, but it would probably break some templates that are using them regardless of whether they do anything or not. We even have a test asserting that parentheses are broken :(
If this feature is wanted, though, I would be happy to do the necessary work, which would include killing certain portions of the lax parser (which we want to do eventually anyway, right?)
The other option is to have some kind of super-conditional tag or syntax that is only available with liquid-c or the strict ruby parser. That way it could be opt-in and not break existing templates.
Maybe call it cond, if* or if+. Though the fact that fancy expression features work in that tag but not if would be weird.
Or it could be an opt in for expressions. Maybe some special kind of augmented parentheses in which real expression syntax is valid. Maybe something like the magic test command in bash: {% if [this && (that || other)] %}
I don't know if this is really the same issue, but i'd love a not-where clause for filtering lists. IE: {% assign promos = site.pages | where: 'homepage', true | except: 'show', true %}.
That way anything that isn'ttrue will trigger the thing, even if it's not actually a 'falsey' value.
If this is a different issue please let me know; i didn't find this exact thing already reported and wasn't sure if i should create something new.
The dropping of lax and other things in v6 likely means that Shopify is about to auto upgrade/convert all existing non compliant templates they have to be compliant with v6 and the strict mode.
Overall a very positive sign that they will finally be able to make significant progress to taking quirks and limitations like this out of liquid.
I'd say it's probably unlikely they would add something new like this in the major v6 change as it's more about getting a solid foundation.
But definitely see how this unlocks things like this finally making it into versions beyond that even if it's a v6.1
Activity
nickpearson commentedon Sep 13, 2012
To work around this, I've always used nested
if/unlessstatements, which isn't pretty but it works.So, if you have this in a language that has a
notoperator:then you can do this in Liquid:
It can get tricky if you need complex
elselogic, but most times this works for me.phoet commentedon Jun 9, 2013
@dapengme what is your specific usecase? you can also use
var != 'value'fw42 commentedon Jun 16, 2013
Since this is not really an issue but more of a question, and it's pretty old, I will close this for now. Please re-open if necessary.
retorquere commentedon Aug 17, 2014
Without "not", it is quite awkward to express something like "if not p.url contains '/'"
pathawks commentedon Aug 17, 2014
unless p.url contains '/'?retorquere commentedon Aug 17, 2014
That works only for simple, not combined conditions. I've worked around it, but "not" is a legitimate boolop that is not entirely replacable by unless.
cam commentedon Sep 9, 2014
Sometimes it would make a lot more sense to have things that behave like "does not contain", rather than an "unless" statement. It would keep things cleaner and offer more options.
courtyenn commentedon Feb 16, 2015
I agree with Cam and AllThatIsTheCase. It is difficult to check if, for example, a collection of product.tags and customer.tags do not contain the tag "wholesale" without a "not contains" operator because of the combined condition.
fw42 commentedon Feb 19, 2015
Reopened because of #526
Blaisorblade commentedon Feb 19, 2015
From #526:
Ah. Sounds like the problem is the parser support for not, because you're not using a parser generator or something like that — and you can't parse the context free grammar of expressions with parentheses with regular expressions such as
liquid/lib/liquid/tags/if.rb
Line 14 in 12d526a
fw42 commentedon Feb 19, 2015
@trishume and @pushrax might have thoughts
pushrax commentedon Feb 20, 2015
We could totally implement parentheses with the new parsers, but it would probably break some templates that are using them regardless of whether they do anything or not. We even have a test asserting that parentheses are broken :(
If this feature is wanted, though, I would be happy to do the necessary work, which would include killing certain portions of the lax parser (which we want to do eventually anyway, right?)
trishume commentedon Feb 22, 2015
The other option is to have some kind of super-conditional tag or syntax that is only available with liquid-c or the strict ruby parser. That way it could be opt-in and not break existing templates.
Maybe call it
cond,if*orif+. Though the fact that fancy expression features work in that tag but not if would be weird.Or it could be an opt in for expressions. Maybe some special kind of augmented parentheses in which real expression syntax is valid. Maybe something like the magic test command in bash:
{% if [this && (that || other)] %}50 remaining items
mahnunchik commentedon Dec 7, 2021
Any news?
pigsflew commentedon Dec 21, 2021
I don't know if this is really the same issue, but i'd love a not-where clause for filtering lists. IE:
{% assign promos = site.pages | where: 'homepage', true | except: 'show', true %}.That way anything that isn't
truewill trigger the thing, even if it's not actually a 'falsey' value.If this is a different issue please let me know; i didn't find this exact thing already reported and wasn't sure if i should create something new.
rianfloo commentedon Jan 12, 2022
Any news 9 years later? :(
moseleyi commentedon Feb 23, 2022
Soon to be 10.. still no solution for this?
fer-rum commentedon Apr 20, 2022
Maybe they want to keep it around as a running gag. 🤡
TenguTech commentedon Jul 4, 2022
Yes, more logic in Liquid would be nice.
On the time period to resolve this issue, there is an Atlassian Cloud Jira card in that will be 11 years old in 4 days :)
erikplatte commentedon Jul 28, 2022
To use a NOT statement in Liquid this worked for me:
Simply put the NOT true in an else statement
{% if a=12 %}
[put if true result here]
{% else %}
[put if NOT true result here]
{% endif %}
TWiStErRob commentedon Jul 28, 2022
@erikplatte
{% unless a=12 %}exists for that reason... the problem in this issues is more complex boolean expressions, e.g.a and not b.UlyssesZh commentedon Dec 5, 2022
+1 for the feature! I need to express the following logic:
{%- if !layout.no_gitalk and !page.no_gitalk and (jekyll.environment == 'production' or site.debugging_gitalk) -%}Currently I will need three nested if/unless to express this logic...
tim-harding commentedon Jul 23, 2024
Is this on the table 11 years later? Would love a simpler way to negate an assignment than this:
Merge pull request Shopify#138 from BerkeleyTrue/feature/noop-server
josephcagle commentedon Dec 16, 2025
yeah I kind of need an expression like
not (...)right now...isaacbowen commentedon Dec 17, 2025
miiight be a thing in liquid 6.0.0? see #2017, which appears to be sketching out that future
rickydazla commentedon Dec 17, 2025
@isaacbowen unless I'm missing something i don't see anything in that PR which would infer support for
notbeing planned?evulse commentedon Dec 17, 2025
The dropping of lax and other things in v6 likely means that Shopify is about to auto upgrade/convert all existing non compliant templates they have to be compliant with v6 and the strict mode.
Overall a very positive sign that they will finally be able to make significant progress to taking quirks and limitations like this out of liquid.
I'd say it's probably unlikely they would add something new like this in the major v6 change as it's more about getting a solid foundation.
But definitely see how this unlocks things like this finally making it into versions beyond that even if it's a v6.1