Create counter inside for loop and paginate

Solved
Rudiarsana
New Member
3 0 0

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 %}

 

 

0 Likes
tim
Shopify Expert
2937 141 985

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.

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes
Rudiarsana
New Member
3 0 0

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)

0 Likes
tim
Shopify Expert
2937 141 985

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.

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
Rudiarsana
New Member
3 0 0

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

0 Likes