All things Shopify and commerce
Hi All, I want to create counter variable inside for loop that has paginate,
I've use app to create metafields, and check that metafield value in loop
How to get the total of each variable value ? Can anyone give me hint how the right way to do this ?
Here's my code
{% assign blog = blogs.review %}
{% paginate blog.articles by 3%}
{% if blog.articles_count > 0 %}
{% for article in blog.articles %}
{% case article.metafields.post_attribute.post_rating %}
{% when '5' %}
{% assign star5 = star5 | plus: 1 %}
{% when '4' %}
{% assign star4 = star4 | plus: 1 %}
{% when '3' %}
{% assign star3 = star3 | plus: 1 %}
{% when '2' %}
{% assign star2 = star2 | plus: 1 %}
{% else %}
{% assign star1 = star1 | plus: 1 %}
{% endcase %}
{% endfor %}
{% endif %}
{% endpaginate %}
Solved! Go to the solution
This is an accepted solution.
Pagination is limited to 50 objects per page unless you're using {% layout none %}, in which case it's much higher (250/1000? -- check this thread, for example).
So if I absolutely had to do what you want, I'd use a layout none page to calculate these counters and retrieve this data with Ajax from your blog page.
Looks right to me.
Keep in mind that because your loop is inside pagination and you paginate by 3, the code will loop over 3 articles shown on current page.
If the code is outside pagination, it will loop over first 50(? not quite sure what's the limit for articles) articles.
Well actually thats the problem Tim, I want this variable count total item not just on 3 looping article on the paginate object
Can we achieve that in shopify ? Because if I didn't use paginate it will limit only 50 items (limit for article)
This is an accepted solution.
Pagination is limited to 50 objects per page unless you're using {% layout none %}, in which case it's much higher (250/1000? -- check this thread, for example).
So if I absolutely had to do what you want, I'd use a layout none page to calculate these counters and retrieve this data with Ajax from your blog page.
Ahhh I forgot about ajax, I've try to put it in iframe (the page with layout none) but the iframe is cant display it
Will try to use ajax, thx for the hint
Portrait of Stephen positioned next to an image of planet Earth, with the Stephen's World ...
By JasonH Mar 18, 2024Digital marketers and app developers have tracked activity in apps and websites for yea...
By Ollie Mar 13, 2024February was an exciting month with Shopify Editions, informative webinars, and more! F...
By JasonH Mar 7, 2024