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

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


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.


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


{{ with .Resources.Match "comments/*.json" }}
  {{ range . }}
    {{ $d := .Content | transform.Unmarshal }}
      Author: {{ $ }}<br>
      Date: {{ $ | time.AsTime | time.Format ":date_long" }}<br>
      Body: {{ $d.body | safeHTML }}
  {{ end }}
{{ end }}
1 Like

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

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.

1 Like

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).

1 Like

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