2

I am creating a blog on apostrophe JS and I want the first blog post in the index to have a longer preview than the rest of the blogs in the index. Is there a way to get the index of the loop? Or a different way to do this?

{%- for piece in pieces -%}
  {{ renderBlogListing(piece) }}
{%- endfor -%}
Smittey
  • 2,475
  • 10
  • 28
  • 35

1 Answers1

2

Yes, you can. Apostrophe uses Nunjucks, which is a JavaScript port of Jinja, which is also well known in its PHP port, Twig.

All of these let you access the loop index in two ways:

loop.index: the current iteration of the loop (counting from 1)

loop.index0: the current iteration of the loop (counting from 0)

See the nunjucks documentation for quite a bit more.

Tom Boutell
  • 7,281
  • 1
  • 26
  • 23