On my website, I show some products with a condition – if the product has a test
tag:
{% if product.tags contains 'test' %}
// render product
{% endif %}
And this way I get only some products, but the native product filter still displays the count of all products. I’ll check it this way:
{% for filter in collection.filters %}
{% for value in filter.values %}
{{ value.count }},
{% endfor %}
{% endfor %}
And like I said, I get the full amount of products. But I want to get only the number of products that I displayed by condition. Can you please tell me how to do this? Thank you!
2
Answers
In the for-loop that you use to render products you can create a
count
variable and use it later.pseudocode:
this solution isn’t elegant but the easiest one. If you need a counter in ‘product-div’ you can create two exact same for-loops: one for counting and second one for rendering.
Again, this solution is not the most clever one but the beauty lies in simplicity and simple code is always the best one
I think what you need to do is the following:
In liquid this look pretty much like this: