skip to Main Content

I would like to show a custom div after the 5th product in my collection in shopify. Does anyone know how I can do this in liquid?

2

Answers


  1. End the end of the for loop for the products, put a conditional like

    {% if forloop.index == 5 %}
       <div></div>
    {% endif %}
    
    Login or Signup to reply.
  2. liquid for loop iteration

    use limit/ offset

    {% for item in array limit: 4 %}
      item less than or equal to 4
    {% endfor %}
    {% for item in array offset: 4 %}
      item greater than 4 (5)
    {% endfor %}
    

    or use forloop.index

    {% for item in array %}
      {% if forloop.index < 5 %}
        do something for less than 5
      {% else %}
        do something greater than or equal to 5
      {% endif %}
    {% endfor %}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search