Search code examples
jekyllliquid

How do I access a collection field defined in _config.yml?


As outlined in Jekyll's Collections docs, I've added an additional field to my collections. Here's part of my _config.yml:

collections:
  algebra1-2:
    title: Algebra 1-2
    output: true

How can I access the title field in pages and layouts?

I've tried {{ page.collection.title }} (and a dozen other permutations) with no luck. However, I have found that {{ page.collection }} will render algebra1-2.

Edit: I'm not checking whether or not the page belongs to the collection, and also am trying to avoid conditionals and looping over all pages, as this answer recommends.


Solution

  • I found that this is possible using the following syntax: {{ site.collections[1].<field> }}.

    So, given the example above, {{ site.collections[1].title }} will evaluate to Algebra 1-2.