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
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.
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.
User | Count |
---|---|
11 | |
7 | |
7 | |
7 | |
7 |