Data Repeat

The data-repeat attribute generates repeated HTML from arrays in your data. Write the template once and Cook stamps it out for each item at build time.

Basic usage

Add data-repeat to any element. The value specifies which array to iterate and a name for the current item:

Cook outputs one <li> for each item, with template strings resolved:

<ul> <li><strong>Fast Builds</strong> &mdash; Sub-second builds for most sites</li> <li><strong>Zero JS</strong> &mdash; No client-side framework required</li> <li><strong>Markdown</strong> &mdash; Write content in Markdown with frontmatter</li> </ul>

Nested data access

Use dot notation to reference arrays inside nested objects:

Limit and offset

Control how many items to render and where to start with pipe modifiers:

Offset is applied first, then limit. So offset:2 | limit:5 skips the first 2 items and takes the next 5.

Index variable

Access the current iteration index by adding a second variable name after a comma:

The index is zero-based.

Template strings in attributes

Template variables work in attributes on the repeated element itself, not just in its children:

Using with collections

Markdown collections built during the build process are available through the collections namespace. If you have Markdown files in src/blog/, Cook auto-generates a collections.blog array:

Collection items have properties from their front matter (title, description, date, etc.) plus a url field generated by Cook.

Using with components

Repeat runs before component expansion in the build pipeline. This means you can repeat a custom element and each copy gets expanded individually:

Each repeated <product-card> is expanded into its full component template with the correct attribute values.

Expression syntax

The full expression format is:

dataPath | offset:N | limit:N as itemName, indexName
  • dataPath -- dot-notation path to an array (e.g., features, collections.blog)
  • offset:N -- optional, skip the first N items
  • limit:N -- optional, take at most N items
  • itemName -- required, variable name for the current item
  • indexName -- optional, variable name for the zero-based index

The data-repeat attribute is removed from the output by default.