Eleventy Collections Not Building Fix
In this tutorial, you'll learn about Eleventy Collections Not Building Fix. We cover key concepts, practical examples, and best practices.
The Problem
Eleventy collections return empty arrays or missing items. A template uses collections.posts but no items appear. Tags defined in frontmatter may not match the collection name in templates.
Quick Fix
Step 1: Verify tags in frontmatter
---
# Wrong — tags as string instead of array
tags: post
# Wrong — different tag name
tags: blog
# Right
tags: ["post"]
---
Expected output: The item appears in collections.post.
Step 2: Use the correct collection name in templates
{# Wrong — using plural instead of singular #}
{% for item in collections.posts %}
{# Right — Eleventy uses singular tag name #}
{% for item in collections.post %}
Expected output: The collections.post array contains matching items.
Step 3: Check the template directory
Eleventy processes files in the input directory (default: current directory). Files outside the input directory are ignored:
// .eleventy.js
module.exports = function(eleventyConfig) {
return {
dir: {
input: 'src',
includes: '_includes',
output: 'dist',
},
};
};
Expected output: Only files and directories within the input directory are processed.
Step 4: Use the dump filter for debugging
{# Add temporarily to see collection contents #}
<pre>{{ collections.post | dump(2) }}</pre>
Expected output: Shows the full structure of the collection, including all items and their data.
Step 5: Create custom collections in .eleventy.js
module.exports = function(eleventyConfig) {
eleventyConfig.addCollection('featured', function(collectionApi) {
return collectionApi.getFilteredByTag('post')
.filter(item => item.data.featured);
});
};
Expected output: The featured collection includes only posts with featured: true.
Step 6: Check for pagination configuration
---
pagination:
data: collections.post
size: 10
alias: posts
---
Ensure data points to an existing collection. If the collection name is wrong, pagination produces no pages.
Step 7: Use getFilteredByGlob for file-based collections
eleventyConfig.addCollection('projects', function(collectionApi) {
return collectionApi.getFilteredByGlob('src/projects/*.md');
});
Expected output: Files matching the glob pattern are returned regardless of frontmatter tags.
Step 8: Check for permalink conflicts
If multiple items resolve to the same output path, Eleventy overwrites them:
---
permalink: /post/ # Wrong — same permalink for multiple posts
---
Use unique permalinks for each item.
Prevention
- Use array syntax for tags:
tags: ["post"] - Reference collections by singular tag name:
collections.post - Use
dumpfilter to debug collection contents - Create custom collections for complex groupings
Common Mistakes with collections
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists
These mistakes appear frequently in real-world ELEVENTY code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro