Skip to content

Jekyll Collection Error Fix

DodaTech Updated 2026-06-24 1 min read

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.

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: true to generate individual pages for each collection item
  • Use site.projects only after the collection is defined

Common Mistakes with collection error

  1. Overlapping type class instances that cause GHC to reject the program with ambiguous dispatch errors
  2. Non-exhaustive pattern matches that compile with warnings then crash at runtime
  3. Misunderstanding that String is [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

### How do I create a custom collection in Jekyll?

Add the collection name to _config.yml under collections:, then create a folder prefixed with _ (e.g. _projects/) and add markdown files.

Why does my collection show no pages?

Ensure the collection has at least one file and the files are not drafts. Set output: true in the config to generate pages for collection items.

How do I sort collection items by a custom field?

Use {% assign sorted = site.projects | sort: 'priority' %} in your Liquid template to sort by frontmatter values.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro