Page variable name in for loop using data files

Ah! Okay, I completely misunderstood your question, so let’s try that again :slight_smile:

That said, I am unsure what you are looking to do as your code examples are a little confusing, but I am hopefully getting what you want based on the following two answers.

Option #1: Get a specific data file based on the YAML front matter

In this example, you dynamically access a data file based on a variable you define in the front matter. For example, you want to get the list of items in a JSON file located at site.data.configs.items.

page.markdown yaml front matter

---
parent: configs
---

Code

{% assign myData = site.data[page.parent].items %}

{% for data in myData %}
  your code...
{% endfor %}

The assign tag will create the myData data source dynamically based on what you put in the parent yaml front matter. Note that you do not put a . (period/dot) between data and [page.parent] or that will result in a warning from Jekyll.

Option #2: Filter data based on YAML front matter

In this example, you have the hard-coded data source, but you want to filter the data based on something listed in the front matter.

page.markdown yaml front matter

---
filter: title
---

Code

{% assign myData = site.data.configs.items | where_exp: 'item', 'item.title == page.filter' %}

{% for data in myData %}
  your code...
{% endfor %}

I hope that helps!

edit: changed where to where_exp