1
votes

config.yml defines collectio eggs

collections:
  eggs:
    output: true

A folder _eggs has a document with front matter

I can access the collection label so:

{{ site.collections[0].label }}

which returns "eggs" but not so

{{ site.eggs.label }}

which returns nothing as does this:

{{ site.eggs }}

The documentation about collections at https://jekyllrb.com/docs/collections/#liquid-attributes does not make much sense to me: "The collections are also available under site.collections, with the metadata you specified". In an issue at github the authors say, that the collections field was (silently?) dropped (https://github.com/jekyll/jekyll/issues/4392).

I am currently evaluating Jekyll and this causes doubts where it stable, has up to date docs and has other pitfalls ahead.

Do I misunderstand the docs? Why does the above access to collection metadata not work.

1
Do you need to simply get the label of your collection? There's a solution in the linked issue, but I'm not sure if that's the correct answer. Also, is {{ site.eggs }} empty for you? That one should return all eggs.jpvillaisaza
it should return all eggs, but the output is empty. reading docs and the issues i dropped jekyll already.citykid

1 Answers

1
votes

The metadata of each collection is available with site.collections, that means, it will return an array of the collections with its metadata.

If one access a collection directly, like site.eggs, there won't be metadata available, but an array of all the collection files, i.e. all the files in the _eggs folder.

example

To display the contents of site.eggs you can iterate over each file, consider having the following file in /_eggs/item.yml

---
title: "Jekyll is awesome"
---

Then you can display it in /index.yml like:

{% for egg in site.eggs %}
{{egg.title}}
{% endfor %}

Output:

Jekyll is awesome