skip to Main Content

{{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


  1. What object type is item from (products, articles etc.)?
    Maybe you can use this code:

    {% if item == "VideoDrop" or item == "PostDrop" %}
       {% assign image = image2 %}
    {% else %}
       {% assign image = image1 %}
    {% endif %}
    

    If there are whitespaces on the start/end of the string, you can use this:

    {% if item contains "VideoDrop" or item contains "PostDrop" %}
    

    edit:
    If you want to check, if product has assigned collections named VideoDrop or PostDrop, you can use this code:

    {% for collection in product.collections %}
        {% assign item = collection.title %}
        {% if item == "VideoDrop" or item == "PostDrop" %}
           {% assign image = image2 %}
        {% else %}
           {% assign image = image1 %}
        {% endif %}
    {% endfor %}
    

    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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
  3. 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 set type 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!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search