{{item}}
is an object but when used like this it echoes VideoDrop
or PostDrop
I need to know which one before the liquid proccesses in the dom… Example:
{% if item == "VideoDrop" %}
{% assign image = image2 %}
{% else %}
{% assign image = image1 %}
{% endif %}
but the if
always returns false… What is the correct way to check the value of {{item}}
?
3
Answers
What object type is
item
from (products, articles etc.)?Maybe you can use this code:
If there are whitespaces on the start/end of the string, you can use this:
edit:
If you want to check, if product has assigned collections named VideoDrop or PostDrop, you can use this code:
But the code above will result in image2 overwritten by image1 in some cases. It would be better if you could expand your question and show us, what are you trying to achieve.
You’ll need to call a specific value inside the object to use it in statements.
It could be {{ item.type }} for example.
You need to check object documentation to retrieve value you need inside.
In Shopify, an
xxxDrop
response is a placeholder for “The thing that you’re trying to print to the screen can’t be printed to the screen directly”You will need to check for a property on the object to get the behaviour you’re after. A great resource is the Shopify Liquid Reference (also linked in the top of the Shopify theme editor in a really easy-to-miss-spot: right after the “Older Versions” link beside the file name).
Checking
item.type
can sometimes help, but Shopify doesn’t settype
for absolutely every kind of object, so before using anything you’ll want to test it to make sure you’re getting the info you expect. (item.type
is mainly set for the types of objects that can be returned in search results… and not much else)Hope this helps!