Liquid, JavaScript, themes, sales channels
{% if product.tags contains prod.title %} is not working. If I pass the static value with quote like- {% if product.tags contains '467455' %} , it is working but pass the variable, not working. Please guide.
<ul class="related-products">
{% paginate collections.all.products by 1000 %}
{% for prod in collections.all.products %}
{%- comment -%}here the issue if I use static value like='785643754', it is working but when pass the variable. it is not working {%- endcomment -%}
{% if prod.tags contains product.id %}
<li>
<div class="image">
<a href="{{ prod.url | within: collections.all }}" title="{{ prod.title | escape }}">
{{ prod.featured_image | product_img_url: image_size | img_tag }}
</a>
</div>
<h1 class="product-title" itemprop="name">
<a href="{{ prod.url | within: collections.all }}" title="{{ prod.title | escape }}">{{ prod.title }}</a>
</h1>
<h2 class="product-price" itemprop="price">
<span id="ProductPrice">{{ prod.price | money }}</span>
{%- if prod.compare_at_price > prod.price -%}
<span id="ComparePrice">
<s class="reduced-price">{{ prod.compare_at_price | money }}</s>
</span>
{%- endif -%}
</h2>
</li>
{% capture counter %}{{ counter }}*{% endcapture %}
{% endif %}
{% endfor %}
{% endpaginate %}
</ul>
Please help that how to fix. Its urgent
**Unsolicited mentioned removed by Community Moderator**
I have read your code. And can't find '{% if product.tags contains prod.title %}'.
Most close one is '{% if prod.tags contains product.id %} ', and the problem is 'product.id', you have not define 'product', so it should be 'prod.id'
Hi @Kani
I have created a liquid file where I want to show related products by tags of current product. So I fetch all products by {% for prod in collections.all.products %}.
Now here, I am finding which products have current product id in tags(all products) {% if prod.tags contains product.id %}, but result not found.
{%- comment -%}{% if prod.tags contains product.id %} current product id = 8201838624999 {%- endif -%} {%- endcomment -%}
{% if prod.tags contains '8201838624999' %} - when replace the product.id with static value of current product, its working.
Then I think you need try to print {{ product.id }}
{{ product.id }}
I print the product.id, it is displaying but in condition, not working.
While I am using {% if prod.type contains product.id %}. It is working. I am confuse
{{ prod.tags | json }} - ["8201838624999","Prints"]
I found the solution for this. Actually you are comparing a string with an integer. Both type should be the same when we use contains. Try the below code it will work
Here converted integer to string so contain work
{% assign product_id = product.id | append: "" %}
You can use like this
{% for prod in collections.all.products %}
{% assign product_id = product.id | append: "" %}
{% if prod.tags contains product_id %}
<h1>Contain</h1>
{% else %}
<h1>Not Contain</h1>
{% endif %}
{% endfor %}
User | RANK |
---|---|
38 | |
28 | |
13 | |
13 | |
9 |
On our Shopify Expert Marketplace, you can find many trusted third party developers and fr...
By Arno Nov 27, 2023You've downloaded the Search & Discovery app from the Shopify App store, and as you're ...
By Skye Nov 8, 2023The year-end shopping season is just around the corner. Is a flash sale on your radar? Are...
By Jasonh Nov 6, 2023