Curvea

CurveaScript

Loops

CurveaScript renders arrays with @for.

Basic loop

@for post in posts
  <article>
    <h2>{{ post.title }}</h2>
  </article>
@end

If the collection path does not resolve to an array, the loop renders no items.

Index

Inside a loop, $index is the zero-based index after the collection options have been applied:

@for item in items
  <p>{{ $index }}. {{ item.title }}</p>
@end

limit

@for post in posts limit 3
  <h2>{{ post.title }}</h2>
@end

offset

@for post in posts offset 3
  <h2>{{ post.title }}</h2>
@end

sort

@for post in posts sort date desc
  <h2>{{ post.title }}</h2>
@end

Ascending order is the default. The direction may be written explicitly:

@for product in products sort title asc
  <h2>{{ product.title }}</h2>
@end

The current parser also treats an omitted sort direction as ascending:

@for product in products sort title

Option processing

Options are read left to right after the collection path. Collection transformation is applied in this order:

  1. sort
  2. offset
  3. limit

A combined example:

@for post in posts sort date desc offset 2 limit 5
  <h2>{{ post.title }}</h2>
@end

Nested blocks

Loops can contain nested @for and @if blocks, all closed with @end.