Skip to content

Handlebars reverse-iteration over collection #1097

Open
@ThePeach

Description

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)?

Metadata

Assignees

No one assigned

    Labels

    educationenhancement: favoriteVanity label! The maintainer likes this enhancement request a lot.feature: 📞 collectionsRelated to Eleventy’s tags/collections feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions