Include file outputting .yml data sifted through local .md file front matter

In another thread for a different but similar objective that has been solved, @mmistakes suggested I put my total set of “collaborators” data in a single .yml file and pull data from there for a subset of contributors via the front matter of the local .md file. The benefits of this are obvious to me, but I can’t seem to get it to work.

Here’s what I have currently…

# _data/collaborators.yml

doe_jane:
  name: "First Last"
  affiliation: "Name of Place"
  affiliation_url: "URL"
  country: "Country"

etc

(Note I’m not pulling the country value in this particular situation. It’s used for some thing else.)

<!-- _includes/authors.html -->

<section>
  <ul>
    {% for author in site.data.collaborators %}
      <li>{{ author.name }}<sup>{{ forloop.index }}</sup></li>
    {% endfor %}
  </ul>
  <ol>
    {% for author in site.data.collaborators %}
      <li><sup>{{ forloop.index }}</sup><a href="{{ author.affiliation_url }}">{{ author.affiliation }}</a></li>
    {% endfor %}
  </ol>
</section>
<!-- local .md file -->

---
collaborators: [doe_jane, jones_jim]
---

...

{% include authors.html %}

But the only thing that outputs is a <sup> number for every name in the .yml file, which at least tells me the file is being read.

But the problem is that no other data is output, and it does not seem to be filtering out data for only the specified people in the .md front matter, per the example above where I’m just calling Jane and Jim instead of everyone in the file.

I was looking at Jekyll’s Data File examples, but they don’t give an example that describes my situation.

I tried putting the markup that’s in the _includes/authors.html file directly in the local .md file, but the same thing results – no actual data values, and no selection by the indicated names in the .md front matter.

Something’s amiss with the liquid somewhere. Can anyone clarify?

One small change to your data file:

- 
  doe_jane:
  name: "Jane Doe"
  affiliation: "Name of Place"
  affiliation_url: "URL"
  country: "Country"
-
  doe_john:
  name: "John Doe"
  affiliation: "Name of Place"
  affiliation_url: "URL"
  country: "Country"

Though thinking about what you want to do you’ll need a more complex set of for loops I think. The example on the Jekyll docs works good when you’re trying to pull in one record of data. In your case you want several, so you’ll need to construct a loop within a loop I think.

You’ll probably need to use the where filter too as the current loop will just output all authors in your collaborators.yml file. The challenge will be to break apart the array of authors to check your data file against. In all the examples I’ve seen it’s much simpler because they’re just checking against a string like doe_jane.

I’m sure it can be done though.

Thanks for the pointers.

Thinking about this, I may have to use a combination of 2 methods for now.

The .yml file works great for the index page, where all collaborators will be listed. Your suggestion actually solved a problem there I had yet to come to. So that’s great! The repo maintainers can keep that file up to date when creating new “outside collaborators” on the repo.

But on individual definition pages, contributing authors can add their own front matter lines there as I was originally thinking about it, which we have working at this point.

It may not be the ultimate single-source solution, but it works in the meantime.