← Back to 11ty notes

Reusing 11ty listing templates

• 🍿 1 min. read

I've been starting to tidy up my blog (which uses 11ty) and for ages I'd been creating a listing template for each of my blog, tutorials and design sections.

My listing templates were something like the following, looping through collections:

<ul role="list" class="post-listing">
{% for entry in collections.blog %}
<li class="mb-sm side-by-side"></li>
</ul>

I've been able to replace this by adding frontmatter into my listing index file like: collectionName: blog and then replacing all 3 listing file with a single one which contains the following:

<ul role="list" class="post-listing">
{% for entry in collections[collectionName] %}
<li class="mb-sm side-by-side"></li>
</ul>

It's a small improvement, but all of these slowly mean I can run my blog with less code, which makes me happy!

← Back to 11ty notes