Jekyll Collection Error Fix
In this tutorial, you'll learn about Jekyll Collection Error Fix. We cover key concepts, practical examples, and best practices.
The Problem
Liquid Exception: undefined method `each' for nil:NilaiClass in /_layouts/default.html
Custom collections output nil when the collection has not been defined in _config.yml.
Wrong
# _config.yml — no collection defined
Trying to access site.projects in a template:
{% for project in site.projects %}
<h2>{{ project.title }}</h2>
{% endfor %}
Output: Liquid Exception: undefined method 'each' for nil:NilaiClass
site.projects is nil because the projects collection is not registered.
Right
Define the collection in _config.yml:
collections:
projects:
output: true
permalink: /projects/:title/
Create a collection file: _projects/my-project.md:
---
title: My Project
---
Project description here.
Output: each project renders at /projects/my-project/.
Prevention
- Always define custom collections in
_config.yml - Set
output: trueto generate individual pages for each collection item - Use
site.projectsonly after the collection is defined
Common Mistakes with collection error
- Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
- Non-exhaustive pattern matches that compile with warnings then crash at runtime
- Misunderstanding that
Stringis[Char]with poor performance for large text operations
These mistakes appear frequently in real-world JEKYLL 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