eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Handlebars reverse-iteration over collection

Open ThePeach opened this issue 4 years ago • 3 comments

Hello, I'm going through the pleasure/pain in converting my blog into 11ty. The stack I was on before was Metalsmith and Handlebars, and as you can imagine I'm trying to avoid rewriting the templates, leaving them in Handlebars (and also because compact and logic-less).

I've found extremely useful the eleventy-base-blog and I've taken from there the way tags pages (i.e. a list of posts filed under a specific tag, without pagination) are generated (see more at tags.njk.

My tags.md file is:

---
pagination:
  data: collections
  size: 1
  alias: tag
  filter:
    - all
    - posts
    - newestPosts
renderData:
  title: "{{ tag }} articles"
permalink: "/tags/{{ tag | slug }}/"
layout: posts-list.hbs
---

And the posts-list.hbs template is:

---
layout: base.hbs
---
<main id="main">
  <!-- list of articles -->
  <header class="main__header">
    <h2 class="title-fancy" tabindex="0">
      {{ tag }} articles
    </h2>
  </header>

  <ul class="listing">
    {{#each (lookup collections tag) }}
    <li>{{> partials/article-excerpt }}</li>
    {{/each}}
  </ul>
</main>

Now the problem is that I cannot seem to find a decent method to reverse-iterate the specific tag collection, while this is trivial when creating a pagination by using the reverse: true option.

Any idea? Or should I give up in this specific instance, either by starting to use Nunjucks, or by creating a Handlebar filter (I guess)?

ThePeach avatar Apr 14 '20 08:04 ThePeach