# Running \`load\_data\` on co-located files

**URL:** <https://zola.discourse.group/t/running-load-data-on-co-located-files/1339>\
**Category:** Support\
**Created:** [May 31, 2022, 9:09pm UTC](https://zola.discourse.group/t/running-load-data-on-co-located-files/1339 "2022-05-31T21:09:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwcz](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/mwcz/32/579_2.png) [@mwcz](https://zola.discourse.group/u/mwcz)\
**Post date:** [May 31, 2022, 9:09pm UTC](https://zola.discourse.group/t/running-load-data-on-co-located-files/1339/1 "2022-05-31T21:09:02Z")

</div>

I have some co-located json files that I want to run `load_data` on from `page.html`, but I’m looking for a better way to find the json file’s paths. The structure is like this:

```nohighlight
content
├── post1
│ ├── index.md
│ └── my_data.json
├── post2
│ ├── index.md
│ └── my_data.json
└── post3
    ├── index.md
    └── my_data.json

```

Currently I’m looping through `page.assets` looking for the asset with the right filename, like this:

```django
{# find the path to my_data.json file path #}
{% for asset in page.assets %}
    {% if asset is ending_with("my_data.json") %}
        {% set_global my_data = load_data(path="content" ~ asset) %}
    {% endif %}
{% endfor %}

```

But it seems like this should be a one-liner. If there was a `page.relative_dir`, I could do this:

```django
{% set_global my_data = load_data(path="content" ~ page.relative_dir ~ "my_data.json") %}

```

Or even better, if `load_data` paths could be relative to the page if it starts with `./`:

```django
{% set_global my_data = load_data(path="./my_data.json") %}

```

Or did I miss a simple way that’s already possible?

---

<div class="post-metadata">

**Author:** ![mwcz](https://yyz2.discourse-cdn.com/free1/user_avatar/zola.discourse.group/mwcz/32/579_2.png) [@mwcz](https://zola.discourse.group/u/mwcz)\
**Post date:** [June 2, 2022, 6:14pm UTC](https://zola.discourse.group/t/running-load-data-on-co-located-files/1339/2 "2022-06-02T18:14:58Z")

</div>

I came up with a solution that works well enough for my use case: storing the path to `my_data.json` in each post’s `[extra]`.

**content/my\_post/my\_post.md**

```auto
[extra]
my_data_path = "content/my_post/my_data.json"

```

**templates/page.html**

```auto
load_data(path=page.extra.my_data_path)

```

Since my posts are generated by a script, the `[extra] my_data_path` can be filled in automatically for each new post. That’s fine since in my case, all the names and paths are predictable.

Still, it would be very nice to be able to load data relative to the markdown file, `load_data(path="./my_data.json")`. I took a stab at implementing that in Zola but it seems like a pretty big change to give the load\_data function access to anything about the current Page.

---

<div class="post-metadata">

**Author:** ![keats](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@keats](https://zola.discourse.group/u/keats)\
**Post date:** [June 3, 2022, 9:36pm UTC](https://zola.discourse.group/t/running-load-data-on-co-located-files/1339/3 "2022-06-03T21:36:36Z")

</div>

> [@mwcz](#):
>
> Still, it would be very nice to be able to load data relative to the markdown file, `load_data(path="./my_data.json")`.

Yeah, I think that would be too much of a change.
