debite
debite

Reputation: 444

Using a collection for sub pages in Jekyll results in Liquid Exception

To maintain clarity I like to keep all template files for sub pages in a directory named _pages. As Jekyll ignores all directories starting with _ I need to add the following to my _config.yml:

include:
  - _pages

Even though this already works quite well, a more convenient way to achieve the same results would be to use a collection for all sub pages. This way the sub pages could be targeted with type: pages when defining defaults like shared layouts or meta data.

collections:
  pages:
    output: true

While the above works like a charm for another project, it throws the following exception when using it for my current project:

Liquid Exception: wrong number of arguments (given 0, expected 1) in /_layouts/content.html

I have no idea how the switch from the include folder method to the collection method could produce this error. Even more odd is that the message does not provide a line number.

The file content.html is used as primary layout for the sub pages and got the following content:

---
layout: default
---

<div class="o-page o-page--pushed {{ page.style }}">
  {% include navigation.html %}

  <main class="o-page__content{% if page.merge %} u-pv-0x{% endif %}">
    {{ content }}
  </main>

  {% include footer.html %}
</div>

EDIT: I created a repository which reproduces the issue.

Upvotes: 0

Views: 398

Answers (1)

David Jacquel
David Jacquel

Reputation: 52809

The error is raised when you call page.merge. Because :

  • site.pages is already a special group of pages, replacing it by a pages collection is not specially a good idea. Once done, you no longer can reach originals pages trough site.page, but only new collection's elements.
  • When calling page.merge on a collection item, Liquid tries to invoke the Jekyll::Drop::merge method which needs an argument, and not the merge property set in front matter.

Solution : Don't set pages as a collection.

Upvotes: 2

Related Questions