# How to associate / connect between content files (md) and data files

**URL:** <https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518>\
**Category:** support\
**Tags:** metadata, yaml\
**Created:** [September 4, 2026, 2:24pm UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518 "2026-09-04T14:24:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dorpeer91](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dorpeer91/32/26219_2.png) [@dorpeer91](https://discourse.gohugo.io/u/dorpeer91)\
**Post date:** [September 4, 2026, 2:24pm UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518/1 "2026-09-04T14:24:53Z")

</div>

I am working on a personal portfolio website which includes some project pages for films I worked on. They should all have a “credits” section. I want this section across all “movie” pages to have the same style and follow the same structure.

The way I was thinking of approaching this is to have YAML files in the data folder, each with the same file name as the corresponding .md file. Then I would use some function to automatically have the template look for the data source with the same name.

So for example I have movie1.md which would somehow look automatically for a data file under DATA/CREDITS called movie1.yaml

So my questions are:

How would I make this connection inside the template?

Is this even the right approach? I imagine this isn’t an uncommon thing so I assume there’s a ‘right way’ of doing this.

Lastly how would you go about creating a toggle, so that if there is no associated file - it simply isn’t creating that section on the page?

Just for context: I am a non-professional web developer, coming from film/design/animation background. I have some background in HTML and recently learned some CSS. I’m doing this as a personal challenge (And also to get rid of my Wix account), so I have better understanding than a total non-developer, but definitely a lot of holes in my knowledge compared to someone who does it for a living.

Thanks

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 4, 2026, 4:12pm UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518/2 "2026-09-04T16:12:51Z")

</div>

> [@dorpeer91](#):
>
> Is this even the right approach? I imagine this isn’t an uncommon thing so I assume there’s a ‘right way’ of doing this.

I think of the `/data` data shared by many.

If you have data used by one (or e.g. a section) pages, I would recommend looking into page bundles, e.g. YAML files that you load with

> **[transform.Unmarshal](https://gohugo.io/functions/transform/unmarshal/)**
>
> Parses serialized data and returns a map or an array. Supports CSV, JSON, TOML, YAML, and XML.

This is also much more efficient for “big data” (because Hugo can free the memory when it’s not in use anymore).

This way you don’t need to know much about where it’s located, you can do e.g.🙂

```auto
{{ $movie1 := .Resources.Get "movie1.yml" }}
{{ $firstMovie := .Resources.GetMatch "movie*.yml" }}
{{ $movies := .Resources.Match "movie*.yml" }}
{{ $moviesInHomePage := site.Honme.Resources.Match "movie*.yml" }}
{{ $moviesInAssetsRoot := resources.Match "movie.*.yml" }}
{{ $moviesInAssets := resources.Match "**/movie*.yml" }}

```

And variants of the above.

---

<div class="post-metadata">

**Author:** ![dorpeer91](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dorpeer91/32/26219_2.png) [@dorpeer91](https://discourse.gohugo.io/u/dorpeer91)\
**Post date:** [September 5, 2026, 9:27am UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518/3 "2026-09-05T09:27:43Z")

</div>

Thanks for the quick reply!

So you’re saying if the data is only relevant to a specific page, keep it as a data file in that page bundle instead of referencing a data file in the data folder?

---

<div class="post-metadata">

**Author:** ![mriambez](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@mriambez](https://discourse.gohugo.io/u/mriambez)\
**Post date:** [September 5, 2026, 7:29pm UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518/4 "2026-09-05T19:29:06Z")

</div>

> [@bep](#):
>
> If you have data used by one (or e.g. a section) pages, I would recommend looking into page bundles

I tried this a few months ago and Hugo server would often fail to reflect the changes in the watcher. Moving the files to the assets folder and the issue has never recurred since.

---

<div class="post-metadata">

**Author:** ![Travis\_Beckham](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/travis_beckham/32/22067_2.png) [@Travis\_Beckham](https://discourse.gohugo.io/u/Travis_Beckham)\
**Post date:** [September 10, 2026, 2:55pm UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518/5 "2026-09-10T14:55:02Z")

</div>

You could also just store the credits in the frontmatter of movie1.md

```yaml
---
title: Movie 1
params:
  credits:
    director: foo
    producer: bar 
    executive_producer: baz
---

```

Then in the page template, grab the page params…

```go-template
<ul>
  {{ with .Params.credits.director }}<li>Director: {{ . }}</li>{{ end }}
  {{ with .Params.credits.producer }}<li>Producer: {{ . }}</li>{{ end }}
  ...

```

This would keep the movie content and credits all in the same file.

---

<div class="post-metadata">

**Author:** ![dorpeer91](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dorpeer91/32/26219_2.png) [@dorpeer91](https://discourse.gohugo.io/u/dorpeer91)\
**Post date:** [September 11, 2026, 8:17am UTC](https://discourse.gohugo.io/t/how-to-associate-connect-between-content-files-md-and-data-files/57518/6 "2026-09-11T08:17:41Z")

</div>

Yup, that’s also a good option. My initial thought was that it would make the front-matter a bit busy, but it would also make things a bit simpler.
