Reputation: 5000
How do I link yml-defined data to my collection?
I'd prefer to keep all my data about "projects" in an .yml file like so:
---
- id: project-A
- title : Fancy project A
---
- id: project-B
- title : Fancy project-B
... and I have a collection "projects".
I can loop over my yml-defined projects:
{% for case in site.data.projects | sort: 'order' %}
But once on the corresponding "project" page, how do I access the site.data.projects defined data? Is there anyway I can tell Jekyll to augment the collection with this data?
Upvotes: 1
Views: 506
Reputation: 484
If I understand you, you can use the where filter.
{% assign related_project = site.data.projects | where: 'id', page.slug %}
And then loop through related_project. Using 'page.slug' presumes that your slug matches your ID. Slug is also only available in Jekyll 3.1, so if you're using an earlier version, you have to construct the slug (by using 'url' and pulling out part of the path).
That's the most efficient way, that I know, of doing it, but there are others.
Upvotes: 2