Skip to main content
Glama
forloop.md1.44 kB
# forloop Information about a parent [`for` loop](https://shopify.dev/docs/api/liquid/tags/for). ## Properties | Property | Type | Description | |----------|------|-------------| | `first` | boolean | "Returns `true` if the current iteration is the first. Returns `false` if not." | | `index` | number | The 1-based position of the current iteration. | | `index0` | number | The 0-based position of the current iteration. | | `last` | boolean | "Returns `true` if the current iteration is the last. Returns `false` if not." | | `length` | number | Total number of iterations in the loop. | | `parentloop` | forloop | The parent `forloop` object, or `nil` if not nested within another loop. | | `rindex` | number | The 1-based position counting backward from the loop's end. | | `rindex0` | number | The 0-based position counting backward from the loop's end. | ## Example Usage Access the parent loop's index within nested loops: ```liquid {% for i in (1..3) -%} {% for j in (1..3) -%} {{ forloop.parentloop.index }} - {{ forloop.index }} {%- endfor %} {%- endfor %} ``` Output nested iteration positions showing outer and inner loop indices. ## Practical Example Building a comma-separated list of page titles: ```liquid {% for page in pages -%} {%- if forloop.length > 0 -%} {{ page.title }}{% unless forloop.last %}, {% endunless -%} {%- endif -%} {% endfor %} ``` Renders: `About us, Contact, Potion dosages`

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/florinel-chis/shopify-liquid-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server