Exluding the existing product from collection section in product page

Solved
batulkr
Excursionist
42 1 2

Hey everyone,

 

I have a collection snippet that I would like to add to my product page, and I actually can add it there. However, the collection section also shows the product that is in the current product page. I would like to exclude the products that are on view from collection section. What kind of a conditional should I use for that?

Accepted Solution (1)

Accepted Solutions
Evgeniy-M
Excursionist
35 6 7

This is an accepted solution.

Hey @batulkr 

Most likely you include the snippet like this:

{% render 'your-snippet' %}

or 

{% include 'your-snippet' %}

First, you need to pass the current product object:

{% render 'your-snippet', current_product: product %}

Within your snippet most likely you have a loop through products. You need to compare handles of the products:

{% for product in all_products %}
  {% unless product.handle == current_product.handle %}
    <div class="collection-product">...</div>
  {% endunless %}
{% endfor %}
Liquid Ajax Cart — a Javascript library to build Shopify Ajax Carts using plain Liquid templates.

View solution in original post

Replies 3 (3)
Evgeniy-M
Excursionist
35 6 7

This is an accepted solution.

Hey @batulkr 

Most likely you include the snippet like this:

{% render 'your-snippet' %}

or 

{% include 'your-snippet' %}

First, you need to pass the current product object:

{% render 'your-snippet', current_product: product %}

Within your snippet most likely you have a loop through products. You need to compare handles of the products:

{% for product in all_products %}
  {% unless product.handle == current_product.handle %}
    <div class="collection-product">...</div>
  {% endunless %}
{% endfor %}
Liquid Ajax Cart — a Javascript library to build Shopify Ajax Carts using plain Liquid templates.

View solution in original post

batulkr
Excursionist
42 1 2