# Is there an equivalent of .Site.Data for page scope?

**URL:** <https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578>\
**Category:** support\
**Created:** [September 18, 2022, 7:01pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578 "2022-09-18T19:01:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [September 18, 2022, 7:01pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578/1 "2022-09-18T19:01:01Z")

</div>

Hi, is there an equivalent of `.Site.Data` for page scope?  
I want to place some data files to page folder, such as:

```auto
pages/
  foo/
    comments/
      a.json
      b.json
      ...

```

Is it possible to get the `foo/comments` data in the `foo` page like `.Data.comments`?  
I’m able to get the content via page resources, but I don’t know how to parse it to a `map`.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [September 18, 2022, 9:00pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578/2 "2022-09-18T21:00:13Z")

</div>

content/pages/foo/comments/a.json

```json
{
  "author": "John Doe",
  "date": "2022-09-17T13:47:25-07:00",
  "body": "This is a <strong>bold</strong> word in a comment."
}

```

template

```auto
{{ with .Resources.Match "comments/*.json" }}
  <h3>Comments</h3>
  {{ range . }}
    {{ $d := .Content | transform.Unmarshal }}
    <p>
      Author: {{ $d.author }}<br>
      Date: {{ $d.date | time.AsTime | time.Format ":date_long" }}<br>
      Body: {{ $d.body | safeHTML }}
    </p>
  {{ end }}
{{ end }}

```

---

<div class="post-metadata">

**Author:** ![razon](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/razon/32/14882_2.png) [@razon](https://discourse.gohugo.io/u/razon)\
**Post date:** [September 18, 2022, 10:46pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578/3 "2022-09-18T22:46:52Z")

</div>

Thanks a lot, one more question is that, would this become a performance issue if there are a lot of comment files, compare to `.site.data` approach.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [September 18, 2022, 10:56pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578/4 "2022-09-18T22:56:47Z")

</div>

I have no idea how the two approaches compare.

In my example:

- With 1 data file the build time was 55 ms (average of 5 runs)
- With 300 data files the build time was 170 ms (average of 5 runs)

So I think the comparison is irrelevant.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [September 18, 2022, 11:24pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578/5 "2022-09-18T23:24:21Z")

</div>

I ran another test, moving the 300 data files to the data directory (accessed via `site.Data.comments`). The build time was essentially the same at 176 ms (average of 5 runs).

---

<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:** [September 20, 2022, 11:24pm UTC](https://discourse.gohugo.io/t/is-there-an-equivalent-of-site-data-for-page-scope/40578/6 "2022-09-20T23:24:40Z")

</div>

Closed on September 20, 2022, 11:24pm UTC

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