Choens
Choens

Reputation: 1342

Jekyll Data Declared in Post Yaml

I have a file called 2015-12-04-galleries.yml in my _data folder. I can successfully parse it with the following.

{% for gall in site.data.2015-12-04-galleries %}
    <p> {{gall.name}} </p>
    <p> {{gall.address}} </p>
    <p> {{gall.url}} </p>
    <p> {{gall.url_show}} </p>
{% endfor %}

I am going to have a new file once a month. I would like to define a new layout, called event, to handle this. I would like to define the data source in the post yaml. Something like:

---
layout: event
data: 2015-12-04-galleries
---

{% for gall in post.data %}
    <p> {{gall.name}} </p>
    <p> {{gall.address}} </p>
    <p> {{gall.url}} </p>
    <p> {{gall.url_show}} </p>
{% endfor %}

I just can't figure out how to define the data source as a variable in the YAML.

Upvotes: 0

Views: 222

Answers (2)

Maria Coding
Maria Coding

Reputation: 121

As David Jacquel pointed out:

But if you want to generate a page for each gallery, you try Jekyll collections that can automatically generate a page for each collection's item.

Jekyll collections might be a good solution for you. I just replied a question about it, with a step-by-step, so please check it out and tell me if it works for you: Can I generate navigation from folder structure with Jekyll?

Upvotes: 1

David Jacquel
David Jacquel

Reputation: 52789

This will get your datas :

---
layout: event
data: 2015-12-04-galleries
---

{% for gall in post.data[page.data] %}
    <p> {{gall.name}} </p>
    <p> {{gall.address}} </p>
    <p> {{gall.url}} </p>
    <p> {{gall.url_show}} </p>
{% endfor %}

But if you want to generate a page for each gallery, you try Jekyll collections that can automatically generate a page for each collection's item.

Upvotes: 1

Related Questions