I’m building an art website, so most pages have some sort of image gallery. I’d like to have templates for the galleries that I can pass YAML files through, in order to generate a different gallery of images for each page. I’ve managed to get this working for files in the _data folder directly, but I’m stumped on how to pass a YAML file in a _data subfolder.
My project setup looks like this:
site/
_data/
projects/
projectfoo.yml
projectbar.yml
artwork.yml
character-design.yml
_includes/
gallery-cards.html
project-cards.html
projects
projectfoo.md
projectbar.md
artwork.md
character-design.md
Here’s the code from artwork.md:
# Major Projects
{% assign source = "artwork" %}
{% include project-cards.html %}
and the code from project-cards.html, which works:
<div class="card-container">
{% for item in site.data[source] %}
<a href="/projects/{{ item.link }}">
<div class="card">
<image src="{{ item.image }}" alt="{{ item.name }}"></image>
<div class="card-title">
{{ item.name }}
</div>
</div>
</a>
{% endfor %}
</div>
Meanwhile, the code from projectfoo.md:
{% assign source = "site.data.projects.projectfoo" %}
{% include gallery-cards.html %}
and the code from gallery-cards.html, which does not work:
<div class="card-container">
{% for item in [source] %}
<a href="{{ item.link }}">
<div class="card">
<image src="{{ item.image }}" alt="{{ item.name }}"></image>
</div>
</a>
{% endfor %}
</div>
I’ve tried a few different variations of wording the source, including:
source = "projectfoo"
...
{% for item in site.data.projects[source] %}
and
source = "projects/projectfoo"
...
{% for item in site.data[source] %}
I can’t figure out how to do this for the life of me. Is it even possible, or will I have to settle for having all my YAML files in the main _data directory?