1

I have a products object:

assign rel_products = collection.products

How can I check for a specific product within this object? By id preferably. I'm doing this check so I can continue in a for loop:

{% if rel_products contains related_product.id %}
    {% continue %}
{% endif %}

This code above isn't working.

f7n
  • 1,476
  • 3
  • 22
  • 42

2 Answers2

0

I am not very familiar with liquid but the problem in your code snippet looks like you are assigning the collection to the variable rel_products, so you will have to loop through that and then check the id in each iteration. Possibly something like this?

{% for product in rel_products  %} 
    {% if product contains 'Id you want to check' %}
        {% continue %}
    {% endif %}
{% endfor %}
Swagata
  • 622
  • 5
  • 19
0

I think this might be the solution you needed.

{% assign rel_products = collection.products %}

{% for product in rel_products %}
      {% if product.id == 12345789 %}   //123456789 is just an example
          <!-- Something you want to do -->
      {% endif %}
{% endfor %}
Radhesh Vayeda
  • 881
  • 7
  • 20