# Content adapters: using local data

**URL:** <https://discourse.gohugo.io/t/content-adapters-using-local-data/50317>\
**Category:** support\
**Tags:** content-adapters\
**Created:** [June 16, 2024, 10:53am UTC](https://discourse.gohugo.io/t/content-adapters-using-local-data/50317 "2024-06-16T10:53:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![angusm](https://avatars.discourse-cdn.com/v4/letter/a/f6c823/32.png) [@angusm](https://discourse.gohugo.io/u/angusm)\
**Post date:** [June 16, 2024, 10:53am UTC](https://discourse.gohugo.io/t/content-adapters-using-local-data/50317/1 "2024-06-16T10:53:59Z")

</div>

I have a bunch of local data files named `data/news/2024.json`, `data/news/2023.json` etc., each one containing news items that I intend to use to build news pages on a site.

Historically, Hugo has not (AFAIK) provided a way to build pages from data files (a feature available in some other SSGs). In fact, I think that somewhere in the docs there was a stern warning saying “That’s not what it’s for; don’t do this”, or words to that effect.

In other words, there isn’t a way to take my `data/news/2024.json` and get a `news/2024.md` from it. I need to create a stub `news/2024.md` file and then use a layout template to pull in the data from `data/news/2024.json`.

With the new content adapters, however, it looks as if I can create a `_content.gotmpl` file in the appropriate place and then iterate over the local data, e.g.

```auto
{{ range .Site.Data.news }}
...
{{ $page := ... }}
{{ $.AddPage $page }}
{{ end }}

```

This seems to work pretty well, and means that I don’t need to repeat myself: I just put the data files in the `data/news` directory and my pages are generated for me.

My question is: is this a legitimate and safe use of content adapters? It seems reasonable to me, but as it’s not explicitly called out as a possibility in the docs, I wanted to be sure that this wasn’t abusing the feature in a way that might cause it to stop working in some future release.

---

<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:** [June 16, 2024, 11:00am UTC](https://discourse.gohugo.io/t/content-adapters-using-local-data/50317/2 "2024-06-16T11:00:52Z")

</div>

> [@angusm](#):
>
> My question is: is this a legitimate and safe use of content adapters?

Yes it is.

That said:

- I like to think of the `/data` folder as a place for data that is used by many. It’s read into memory and kept there for the entire build.
- For data that’s used once (or twice …) I would recommend putting it in `/assets`, see [transform.Unmarshal | Hugo](https://gohugo.io/functions/transform/unmarshal/#unmarshal-a-resource)

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [June 18, 2024, 11:01am UTC](https://discourse.gohugo.io/t/content-adapters-using-local-data/50317/3 "2024-06-18T11:01:01Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
