Petrus Theron
Petrus Theron

Reputation: 28807

Render Jekyll collection metadata to each output document using layout template

Given a custom Jekyll collection in a folder _stuff, where each document has some metadata, how do I render that metadata using a layout template to an output document? I suspect I need a plugin to do any more than iterating over a collection. E.g. in _config.yml:

collections:
  stuff:
    output: true
    permalink: /stuff/:path

In collection item, e.g. _stuff/thing1.md:

---
title: Thing 1
some_data: 123
layout: stuff-detail
---

Using layout, stuff-detail.liquid:

---
....
---

<div>Stuff Item Data: {{ page.some_data }} (doesn't work)</div>

Upvotes: 1

Views: 503

Answers (2)

eQ19
eQ19

Reputation: 10691

Try to use this code on your layout stuff-detail.liquid:

<div>Stuff Item Data: {{ page.output }}</div>

See how it works as explained here.

Upvotes: 0

Brad West
Brad West

Reputation: 969

In your stuff-detail.liquid file you'll need double brackets around your liquid call: {{ page.some_data }}

Upvotes: 1

Related Questions