Can you combine limit and offset filters in the same for loop?

Solved

Can you combine limit and offset filters in the same for loop?

DanCDN
Shopify Partner
3 0 0

Is there a way to put a for loop with both filters limit and offset like this:

 

{% for variant in product.variants offset: 11 & limit: 21 -%}
{%- endfor %}
 
???
Accepted Solution (1)

NomtechSolution
Astronaut
1245 113 159

This is an accepted solution.

In Liquid, the template language used by Shopify, you can indeed use both the limit and offset filters in a for loop to control the number of iterations and the starting point. However, the syntax is slightly different than what you've provided.

Here's the correct syntax for using the limit and offset filters together in a for loop:

 

{% for variant in product.variants limit: 21 offset: 11 %}
  <!-- Loop content goes here -->
{% endfor %}

 

View solution in original post

Reply 1 (1)

NomtechSolution
Astronaut
1245 113 159

This is an accepted solution.

In Liquid, the template language used by Shopify, you can indeed use both the limit and offset filters in a for loop to control the number of iterations and the starting point. However, the syntax is slightly different than what you've provided.

Here's the correct syntax for using the limit and offset filters together in a for loop:

 

{% for variant in product.variants limit: 21 offset: 11 %}
  <!-- Loop content goes here -->
{% endfor %}