Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
{% 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 %}
- Your Coffee Tip can create magic in coding ☕✨
- Seeking a Shopify Certified Developer? Contact us Shopify Verified partners
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024