Error in Shopify Liquid Reference

Solved
Highlighted
Tourist
8 2 3

Hi all,

 

i am not sure where to post this, but i believe to have found an error/mistake in the official shopify liquid reference.

 

I have reproduced this in my shopify store. I am aware, that there are some store specific settings the shopify staff can define (see my other post), so i am not sure, wether this only happens in my store.

 

On this page:

https://shopify.dev/docs/themes/liquid/reference/basics/true-and-false#truthy

 

The following code is actually wrong. The text will not appear.

 

In the example below, the text "Tobi" is not a boolean, but it is truthy in a conditional:

 

{% assign name = "Tobi" %}

{% if name == true %}
  This text will always appear if "name" is defined.
{% endif %}

 

When checking for == true, Liquid will actually check wether the variable is bool and true, not only if the variable exists.

 

To my understanding, the correct documentation should look something like this:

 

{% assign name = "Tobi" %}

{% if name == true %}
  This text will not appear because 'name' is not bool and not true
{% endif %}

{% if name %}
  This text will appear because 'name' is defined and is not false
{% endif %}

{% if name != empty %}
This text will appear because 'name' is defined and is not empty
{% endif %}
{% if name != nil %} This text will appear because 'name' exists {% endif %}

 

I was debugging like crazy because of this bit on information until it crossed my mind, that there might actually be a mistake in the docs.

 

Can anyone replicate this? And if so, where can i go to suggest an update to the documentation?

 

Kind regards,

Thomas

 

1 Like
Highlighted
Shopify Partner
1807 211 374

This comes straight from Ruby (https://learn.co/lessons/truthiness-in-ruby-readme#what-is-'truthy'-and-'falsey'-in-ruby?) on which Liquid is running. Yes, they shouldn't have had == true in the docs for Truthy, and have it read:

{% assign name = "Tobi" %}

{% if name %}
  This text will always appear if "name" is defined and not assigned nil or false.
{% endif %}

As the only Falsy values are nil/false. 

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
1 Like
Tourist
8 2 3

Thanks Sergiu for your reply and for confirming. Do you know, how i would best approach Shopify to hint at some changes?

0 Likes
Highlighted
Shopify Partner
1807 211 374

Shopify team monitors the community activity, so they may have already made a note. Unfortunately, there is no formal channel I am aware of that would be dedicated to filling in bugs.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
1 Like
Highlighted
Tourist
8 2 3

Thanks. I'll keep an eye on the docs. I'll close the issue as soon as they update it.

Thanks for looking into this!

0 Likes
Highlighted
Tourist
8 2 3

This is an accepted solution.

I contacted the shopify support team and they will forward the info accordingly to get the docs updated.

 

Also, the official channel to report mistakes in the shopify docs is via email to docs@shopify.com. I hope this helps anyone coming across other mistakes in the docs, although i believe the docs are very well written and i have not come across any mistakes in three years, apart the aforementioned mistake.

0 Likes