Skip to content

Instantly share code, notes, and snippets.

@profstein
Last active April 2, 2022 20:48
Show Gist options
  • Save profstein/ede349546adf78740b040e8394dceb33 to your computer and use it in GitHub Desktop.
Save profstein/ede349546adf78740b040e8394dceb33 to your computer and use it in GitHub Desktop.
List of Pages in a Collection (Eleventy)
<ul>
{% for page in collections.post %}
<li>
<a href="{{ page.url }}"> {{ page.data.title }}</a>
</li>
{% endfor %}
</ul>
@profstein
Copy link
Author

This will show all pages that have a tag of post in their front matter. To use a different tag you can change what collection is used. For example:
{% for page in collections.blog %}

@profstein
Copy link
Author

profstein commented Apr 2, 2022

You don't have to use 'page' You can call the page whatever you like as long as it is a valid variable name for the template langugage (Nunjucks is used here). This would also work:

<ul>
  {% for banana in collections.post %}
  <li>
    <a href="{{ banana.url }}"> {{ banana.data.title }}</a>
  </li>
  {% endfor %}
</ul>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment